Android の GPS に関して非常に奇妙な問題があります。com.google.android.gms.location.LocationClient を使用し、15 秒ごとに locationUpdate を要求するアプリケーションがあります。バックグラウンド サービスでホストされ、ユーザーの位置を追跡しています。ほぼ常に完璧に機能しますが、電話が利用可能なロケーションプロバイダー(GPS、Wi-Fi、セルなど)がない場所(地下室、ガレージなど)に長時間あると問題が発生します.. )。その場所を離れて新しい場所を受信した後、デバイス全体がブロックされ、作業を継続するにはハード再起動 (バッテリーの取り外し) が必要です.. この種の動作を見たことがありますか?
startService(new Intent(this, GPSService.class));
そしてこれがサービスです:
public class GPSService extends Service implements LocationListener,
ConnectionCallbacks, OnConnectionFailedListener {
private LocationClient locationclient;
private LocationRequest locationrequest;
private void InitGpsService() {
if (locationclient != null && locationclient.isConnected()) {
return;
}
int resp = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resp == ConnectionResult.SUCCESS) {
locationclient = new LocationClient(this, this, this);
locationclient.connect();
Log.d("Messangero", "Location Client Connect");
} else {
Toast.makeText(this, "Google Play Service Error " + resp,
Toast.LENGTH_LONG).show();
}
}
// Binder given to clients
private final IBinder mBinder = new LocalBinder();
public class LocalBinder extends Binder {
GPSService getService() {
// Return this instance of LocalService so clients can call public
// methods
return GPSService.this;
}
}
public IBinder onBind(Intent arg0) {
return mBinder;
}
public void onCreate() {
super.onCreate();
InitGpsService();
};
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
};
public void onDestroy() {
super.onDestroy();
if (locationclient != null && locationclient.isConnected()) {
locationclient.removeLocationUpdates(this);
locationclient.disconnect();
}
}
public void onConnectionFailed(ConnectionResult arg0) {
// TODO Auto-generated method stub
}
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
PreferencesUtil.LoadSettings(this);
locationrequest = new LocationRequest();
locationrequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationrequest.setInterval(PreferencesUtil.GPSSyncPeriod);
locationclient.requestLocationUpdates(locationrequest, this);
}
public void onDisconnected() {
// TODO Auto-generated method stub
if (locationclient != null && locationclient.isConnected())
locationclient.removeLocationUpdates(this);
}
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
Thread thr = new Thread(new LocationUpdateThread(GPSService.this,
location));
thr.start();
}
}