I am developing an Android application that has its own video recorder feature. For that I need to request RECORD_AUDIO permission from the user. But when I request the permission, it is not showing the prompt to get the permission from the user.
This is my function that checks if the app needs to request permission and it does automatically if required.
private boolean isRecordAudioPermissionGranted()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) ==
PackageManager.PERMISSION_GRANTED) {
// put your code for Version>=Marshmallow
return true;
} else {
if (shouldShowRequestPermissionRationale(Manifest.permission.RECORD_AUDIO)) {
Toast.makeText(this,
"App required access to audio", Toast.LENGTH_SHORT).show();
}
requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO
},AUDIO_RECORD_REQUEST_CODE);
return false;
}
} else {
// put your code for Version < Marshmallow
return true;
}
}
In the onCreate of the Activity, I call the function like this.
if(!isRecordAudioPermissionGranted())
{
Toast.makeText(getApplicationContext(), "Need to request permission", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(), "No need to request permission", Toast.LENGTH_SHORT).show();
}
The app is saying that it needs to request permission, but it is just not prompting the request permission dialog. What is wrong with my code?
This are the permissions I added and use in the manifest file.
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.Manifest.permission.RECORD_AUDIO"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-feature android:name="android.hardware.camera.front"/>
<uses-feature android:name="android.hardware.camera.front.autofocus"/>
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true"/>
<uses-feature android:name="android.hardware.sensor.gyroscope" android:required="true"/>
<uses-feature android:name="android.software.vr.mode" android:required="true"/>
<uses-feature android:name="android.hardware.vr.high_performance" android:required="true"/>
Requesting Android Runtime Permissions For this the following method needs to be called on every permission. checkSelfPermission(String perm); It returns an integer value of PERMISSION_GRANTED or PERMISSION_DENIED.
For this you have to: Go to Phone Settings -> Manage applications. Next, Select Call Recorder in the apps list. Select Permissions.
Requesting permission to record audioTo be able to record, your app must tell the user that it will access the device's audio input. You must include this permission tag in the app's manifest file: <uses-permission android:name="android.permission.RECORD_AUDIO" />
For RECORD_AUDIO permission, correct permission string is
android.permission.RECORD_AUDIO
In your manifest you are using
<uses-permission android:name="android.Manifest.permission.RECORD_AUDIO"/>
which in incorrect and it must be
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With