I am coding an application that track and log the device location with gps, it worked perfectly on API 21 but when I switch to API 26 it stopped working.
I used the request location updates that send pending intent periodically:
public void startLocationUpdates() throws SecurityException
{
String provider = LocationManager.GPS_PROVIDER;
PendingIntent pi = getLocationPendingIntent(true);
//this method keep updating unless we specify it to stop
mLocationManager.requestLocationUpdates(provider, 0, 0, pi);
}
I'm handling the pending intent with this receiver:
public class LocationReceiver extends BroadcastReceiver
{
private static final String TAG = "LocationReceiver";
@Override
public void onReceive(Context context, Intent intent)
{
Log.d(TAG, "Receive an intent");
Location= (Location)intent.getParcelableExtra(LocationManager.KEY_LOCATION_CHANGED);
Log.d(TAG, this + " Got location from " + loc.getProvider() + ": " + loc.getLatitude() + ", " + loc.getLongitude());
}
}
I think it have something to do with this line:
2019-02-08 21:41:05.872 1995-2015/system_process W/BroadcastQueue: Background execution not allowed: receiving Intent { act=com.pproject.runtracker.ACTION_LOCATION flg=0x10 (has extras) } to com.pproject.runtracker/.Controller.LocationReceiver
I'm not sure what this meant though