salut a tous les developpeurs Android du site. apres avoir developpe une application de geolocalisation sur eclipse , je suis passe a la phase de test sur un emulateur via Putty et la tout est ok .le probleme est que apres avoir deploye mon APK sur le telephone adroid(MT65xx Android Phone) , je ne recois plus les Toasts . comment faire pour ecouter le GPS une fois l'application deployee sur un veritable telephone. je tiens a signaler que activer le GPS et le WIFi sur ce dernier et effectuer toutes les configurations necessaires .
VOICI MA classe faisant office de service
package com.locartion.service;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Toast;
public class MonPremierService extends Service {
Criteria criteria = null ;
private LocationManager locationMgr = null;
private LocationListener onLocationChange = new LocationListener()
{
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
String newStatus = "";
switch (status) {
case LocationProvider.OUT_OF_SERVICE: newStatus = "OUT_OF_SERVICE" ;
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE: newStatus = "TEMPORARILY_UNAVAILABLE";
break;
case LocationProvider.AVAILABLE: newStatus = "AVAILABLE";
break;
}
String msg = String.format(getResources().getString(R.string.provider_disabled), provider, newStatus);
Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider)
{
String msg = String.format(getResources().getString(R.string.provider_enabled), provider);
Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider)
{
String msg = String.format(getResources().getString(R.string.provider_disabled), provider);
Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT).show();
}
@Override
public void onLocationChanged(Location location)
{
Double latitude = location.getLatitude();
Double longitude = location.getLongitude();
Double altitude = location.getAltitude() ;
Float precision = location.getAccuracy() ;
Toast.makeText(getBaseContext(),"Voici les coordonnées de votre téléphone : " + latitude + " " + longitude, Toast.LENGTH_LONG).show();
Toast.makeText(getBaseContext(),"Voici les coordonnes de votre telephone : " + altitude + " " + precision , Toast.LENGTH_LONG).show();
String msg = String.format(getResources().getString(R.string.new_location), latitude, longitude , altitude, precision);
Toast.makeText(getBaseContext(), msg, Toast.LENGTH_LONG).show();
}
};
@Override
public IBinder onBind(Intent arg0)
{
return null;
}
@Override
public void onCreate()
{
locationMgr = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
criteria = new Criteria() ;
criteria.setAccuracy(Criteria.ACCURACY_FINE) ;
criteria.setAltitudeRequired(true);
criteria.setBearingRequired(true);
criteria.setCostAllowed(false);
criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
criteria.setSpeedRequired(true);
locationMgr.requestLocationUpdates(locationMgr.getBestProvider(criteria, true) ,1000, 1, onLocationChange);
locationMgr.requestLocationUpdates(locationMgr.getBestProvider(criteria, true), 1000, 1,onLocationChange);
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy()
{
super.onDestroy();
locationMgr.removeUpdates(onLocationChange);
}
}
A Vaincre sans péril on finit par triompher sans gloire -> le Cid de corneille
Toast.makeText(MonPremierService.this,"Voici les coordonnées de votre téléphone : "+ latitude + " "+ longitude, Toast.LENGTH_LONG).show();
Toast.makeText(MonPremierService.this),"Voici les coordonnes de votre telephone : "+ altitude + " "+ precision , Toast.LENGTH_LONG).show();
emission Coordonnees GPS
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.