0
我正在製作一個使用GPS的應用程序。問題出現在您沒有啓用GPS的情況下打開應用程序時,它不會執行任何操作(顯然),但如果您在不退出應用程序的情況下啓用GPS,那麼該應用程序仍然無能爲力。因爲我需要禁用和啓用在我的應用GPS,我需要知道在哪裏的問題從何而來,我會在這裏留下您的一些代碼:如何檢測GPS正在啓用
public class EscuchaLocalizacion implements LocationListener {
private LocationManager gestor;
private TextView view1;
private TextView view2;
private boolean registrado;
private static final float minDistance = 10.0f;
private static final long minTime = 300;
public double _LONG;
public double _LAT;
EscuchaLocalizacion (Context c, TextView t1, TextView t2) {
Log.v("EscuchaLocalizacion", "Construyendo el objeto");
gestor = (LocationManager) c.getSystemService(Context.LOCATION_SERVICE);
registrado = false;
view1 = t1;
view2 = t2;
Log.v("EscuchaLocalizacion", "He terminado de construir el objeto");
}
@Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
_LONG = arg0.getLongitude();
_LAT = arg0.getLatitude();
view1.setText(Double.toString(_LONG));
view2.setText(Double.toString(_LAT));
}
@Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
if(arg0.contentEquals(LocationManager.GPS_PROVIDER)){
Log.w("EscucharLocalizacion","Provider: "
+ LocationManager.GPS_PROVIDER + " was disabled");
}
}
@Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
if(!registrado && arg0.contentEquals(LocationManager.GPS_PROVIDER)){
registrar();
}
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
public void registrar() {
if (gestor.isProviderEnabled(LocationManager.GPS_PROVIDER)){
Log.i("EscucharLocalizacion", "Registrado a " + LocationManager.GPS_PROVIDER);
gestor.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime,
minDistance, this);
registrado = true;
}else {
Log.w("EscucharLocalizacion", "No se pudo registrar a " + LocationManager.GPS_PROVIDER);
registrado = false;
}
}
public void anularRegistro(){
gestor.removeUpdates(EscuchaLocalizacion.this);
registrado = false;
}
}