Marshmallow Runtime Permission onRequestPermissionsResult was nor Called While running playstore Build Apk but working fine the normal debuging Apk.Anyone help me..Thanks.
Here is my code
private void EnablePermissions()
{
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,android.Manifest.permission.RECORD_AUDIO)) {
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.RECORD_AUDIO },
MY_PERMISSIONS_REQUEST_RECORD);
Toast.makeText(MainActivity.this, "Permission Request", Toast.LENGTH_SHORT).show();
// result of the request.
}
// Add a marker in Sydney, Australia, and move the camera.
if (ContextCompat.checkSelfPermission(MainActivity.this,
android.Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(MainActivity.this, "checkSelfPermission ", Toast.LENGTH_SHORT).show();
return;
} else {
Log.d("Permission Denied", "Permission Failed to enable");
Toast.makeText(MainActivity.this, "Permission Failed to enable", Toast.LENGTH_SHORT).show();
}
}
OnRequestPermissionResult Method
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
try {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_RECORD: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the
// contacts-related task you need to do.
ChatActivity();
} else {
Toast.makeText(MainActivity.this, "Permission denied Chat ", Toast.LENGTH_SHORT).show();
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
} catch (Exception e) {
Log.e(Constants.LOG, e.getMessage());
}
}