Ever since I upgraded my device to Android 6.0.1 Marshmallow, Android automatically sets the location mode to High accuracy , when applications with permission android.permission.ACCESS_FINE_LOCATION, try to access the location of my device.
Personally, it seemed to me that this is rather annoying, since setting the location mode to High accuracy significantly discharges the battery of my device. So I need to check from time to time if the location mode has been changed, and manually need to change it back to Battery .
So, I decided to create an application in which it will deploy IntentServicein the background, which will be checked every 30 minutes if the location mode has been changed to High accuracy and will change it back to the Battery .
But the problem that is encountered in this is finding a method that will allow me to change the location mode programmatically.
I tried using the following code, but without using:
public void ChangeLocationMode() {
LocationRequest mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(SetLocationModeService.this, "Location Mode Changed!", Toast.LENGTH_LONG).show();
}
});
}
I also added the following permissions to my AndroidManifest.xml:
<uses-permission android:name="android.permission.LOCATION_HARDWARE"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
But this method does not work at all.
So my question is here,
Is it even possible to change the location mode in Android Marshmallow (or higher)?
If there is any tried and true method, do the same, please consider sharing it.