I need to utilize the microphone with Android M. I've tried setting up a permission group in the manifest, and can't get it working properly. Here's what I've got in the manifest:
<permission-group android:name="android.permission-group.MICROPHONE"
android:label="label"
android:icon="@mipmap/day_icon"
android:priority="360"/>
<permission android:name="android.permission.MICROPHONE"
android:permissionGroup="android.permission-group.MICROPHONE"
android:protectionLevel="dangerous"
android:label="label" />
I've also tried getting the access through code:
if (ContextCompat.checkSelfPermission(getActivity(),
Manifest.permission_group.MICROPHONE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(getActivity(),
new String[]{Manifest.permission_group.MICROPHONE},
REQUEST_MICROPHONE);
}
The alert doesn't show to grant access.
I still don't have access to microphone. Anyone know how get permission for the microphone?
Note: This is only not working for Android M
On your phone, open the Settings app. Tap Privacy. Turn off Camera access or Microphone access.
Here's how: Select Start > Settings > Privacy > Microphone . In Allow access to the microphone on this device, select Change and make sure Microphone access for this device is turned on.
Starting in Android 11, whenever your app requests a permission related to location, microphone, or camera, the user-facing permissions dialog contains an option called Only this time. If the user selects this option in the dialog, your app is granted a temporary one-time permission.
To request microphone, you should be requesting Manifest.permission.RECORD_AUDIO
instead of the permission group Manifest.permission_group.MICROPHONE
.
So, remove the tags <permission/>
and <permission-group/>
in the Manifest because they are to indicate that your want to create new permissions rather than use them.
Then to request the permission just do this:
if (ContextCompat.checkSelfPermission(getActivity(),
Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(getActivity(),
new String[]{Manifest.permission.RECORD_AUDIO},
REQUEST_MICROPHONE);
}
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