Android does not show permission dialog for RECORD_AUDIO
I have added the required permission in android manifest
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
and following code
private boolean checkPermission() {
int result = ContextCompat.checkSelfPermission(this, android.Manifest.permission.RECORD_AUDIO);
if (result == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
}
}
private void requestPermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.RECORD_AUDIO)) {
Toast.makeText(this, "RECORD AUDIO Permission is required.",
Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.RECORD_AUDIO},
PERMISSION_REQUEST_CODE);
}
}
and to check it
if (!checkPermission()) {
requestPermission();
}
however the dialog to ask permission or the screen asking for permission is not shown ,
I am testing on android 6.0 on an emulator
ActivityCompat.shouldShowRequestPermissionRationale()
method only signals if a message should be shown. You should request permission regardless of its return value.Take a look at line 142 in this sample: https://developer.android.com/samples/RuntimePermissions/src/com.example.android.system.runtimepermissions/MainActivity.html#l142