Я пытаюсь получить местоположение GPS для записи в файл и сохранить историю моей программы в фоновом режиме, однако по какой-то причине она не отправляет обновления местоположения, когда я покидаю приложение. есть идеи, чтобы это исправить? кажется, что onLocationChanged(Location location)
перестает работать всякий раз, когда я покидаю приложение или даже действие.
public class GPSBackground extends Service implements LocationListener {
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
} else {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
}
return super.onStartCommand(intent, flags, startId);
}
Мне нужно выполнить свои действия здесь:
@Override
public void onLocationChanged(Location location) {
//All the saving data code is here
}
/**
* @param s
* @param i
* @param bundle
* @deprecated
*/
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
}