I integrated Android Runtime Permission for READ PHONE STATE
for Marshmallow devices. This implementation is working fine and the popup is showing in my application with allow/deny option.
I can click the allow/ deny button for normal marshmallow devices. But in the case of updated android devices(From Lollipop to Marshmallow), the allow button click is not working initial time. This issue is tested and reproduced in Nexus 5 and Nexus 7. Is anything we need to create additional for updated OS? Or is it a Marshmallow issue?
Please check the complete code:
private static final int MY_PERMISSIONS_REQUEST_READ_PHONE_STATE = 101;
if (Build.VERSION.SDK_INT >= 23) {
if(mActivity.checkSelfPermission(Manifest.permission.READ_PHONE_STATE) !=PackageManager.PERMISSION_GRANTED) {
if (this.shouldShowRequestPermissionRationale(
Manifest.permission.READ_PHONE_STATE)) {
showExplanationDialog(mActivity, getString(R.string.dialog_message_phone_state));
} else {
this.requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE},
MY_PERMISSIONS_REQUEST_READ_PHONE_STATE);
}
} else {
handleLoginAPI();
}
} else {
handleLoginAPI();
}
private void handleLoginAPI() {
if (super.isNetworkConnectionAvailable(mActivity)) {
// Api Call from here..
}else{
// No Nw Connection.
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_READ_PHONE_STATE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
handleLoginAPI();
} else if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_DENIED) {
if (this.shouldShowRequestPermissionRationale(
Manifest.permission.READ_PHONE_STATE)) {
showExplanationDialog(mActivity, getString(R.string.dialog_message_phone_state));
}
}
return;
}
}
}