I have requested location permission in my manifest file as follows -
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
I also requested run time permission as follows -
//get location permission
int locationPermissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
if (locationPermissionCheck != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(mContext, "Location permission denied", Toast.LENGTH_SHORT).show();
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_FINE_LOCATION);
} else {
Toast.makeText(mContext, "Location permission granted", Toast.LENGTH_SHORT).show();
}
When I install the app from android studio to a connected device(android 10) then I see no request for location, instead I see the toast message "Location permission denied". Then I go to app permission and see the location permission is denied. Then I allow it, close the app and reopen it and then it works. Then I uninstall the app and install again. And then the location permission is denied again automatically even before I run the app.
I am requesting run time permission from MainActivty and using Fused Location in a foreground service. I tried
((ActivityManager)context.getSystemService(ACTIVITY_SERVICE)).clearApplicationUserData();
with no luck.