I am trying to build an android app with an AppCompatActivity that needs fine location permission after log in. I have managed to configure permission request and and on permission result elsewhere in the app successfully for storage and directory access purposes.
However, in this particular case, I am encountering a weird behaviour which I am not able to debug, and googling/searching on S/O has also not given me what I am looking for.
Basically, after my requestPermissions() method executes and dialog to grant permission appears on screen, a second mysterious dialog is appearing that interrupts the flow of my code. This is causing all sorts issues, as expected.
My request permissions method:
private void requestPermissions() {
Log.i(TAG, "Requesting permission");
ActivityCompat.requestPermissions(
this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
REQUEST_PERMISSIONS_REQUEST_CODE);
}
The permission request dialog successfully opens:
But then, inexplicably, this second dialog opens
Clicking 'OK' on this dialog takes me to the settings > permissions page:
Ideally I would like to avoid this second dialog, as it blocks the flow my code returning to onPermissionRequestsResult method, and creates other cascading issues.
But I am completely unable to identify the source of this second pop up.
My onCreate method:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ButterKnife.bind(this);
getSupportActionBar().hide();
Picasso.with(this).setLoggingEnabled(true);
// Check if user has revoked permissions
if (!checkPermissions()) {
requestPermissions();
}
}
The checkPermissions method:
/**
* Returns the current state of the permissions needed.
*/
private boolean checkPermissions() {
return PackageManager.PERMISSION_GRANTED == ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION);
}
My manifest file has the following permissions declared:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.location.gps"
android:required="true" />
These are all the parts of my code that I could think of for reproducing this issue. But seeing as I am completely unable to narrow down where this second dialog is cropping up from, I understand there might be more things one might need from. Please let me know if so.