private IEnumerator CheckMicPermissionsRoutine()
yield return Application.RequestUserAuthorization(UserAuthorization.Microphone);
_micIsAllowed = Application.HasUserAuthorization(UserAuthorization.Microphone);
Three weird things after deleting the app and rebuilding to device (after clearing cache/data on Android):
The HasUserAuthorization call returns true
Going into the Settings for my app, the Mic is set to be “Denied”
Again, the system modal check never happened
How do all those things coexist?
If I manually go into the App Settings and Allow the Microphone, the app behaves as intended, and I can record. But I clearly can’t expect the user to do this.
Earlier, I was having weird issues with data sticking around (like PlayerPrefs) after deleting the app, I think because I had used Firebase’s App Tester app to distribute a version under the same package name, and it seemed to be doing some weird caching no matter what I did, but I did a total factory reset of my phone and that problem seems to be gone. Still the permission call never happens. Could the phone still think it’s been set as denied pre-factory reset? Or for another reason?
Is there a “not yet set” state for permissions? Or are they simply Denied until they’re Approved? I’m curious if the “Denied” state when I go to the App permissions is simply the default, or an indicator that something in my app has silently caused it be Denied.
I should note that earlier in the app experience, the Camera is requested by means of loading the main scene, which uses an ARCamera / Session / SessionOrigin (they must request it automatically when attached). I am not explicitly asking for anything at that time, certainly not the Mic. I would prefer to wait until later in the app experience when the user is asked specifically to record their voice. I don’t like asking for any permission until it’s clear why it’s needed.
Any ideas? My iOS build is coming near to being launchable, and I REALLY don’t want to delay Android… as an Android user, I’m always annoyed when the platform is deprioritized.
Thanks so much!
I think you’re using the wrong class… As stated in docs - https://docs.unity3d.com/ScriptReference/Application.RequestUserAuthorization.html is only for iOS… It seems the API was never unified. For Android, you want to use https://docs.unity3d.com/ScriptReference/Android.Permission.RequestUserPermission.html
Tomas1856:
For Android, you want to use https://docs.unity3d.com/ScriptReference/Android.Permission.RequestUserPermission.html
Hey @Tomas1856 , Thanks!
Now that I know what class to use I was able to locate this thread that you helped greatly to inform. It will be SO much clearer when there’s a unified API. The current Android API doesn’t really make it clear that the permission isn’t immediately available after coming back from the request. The docs should at least mention it because the example doesn’t imply it either way. The OnApplicationPause event seems like a better way to go than guessing an amount of time to wait 
THANKS SO MUCH for checking the forums and being responsive and communicative. I can’t emphasize how appreciative I am!
Please keep being awesome!
Tomas1856:
I think you’re using the wrong class… As stated in docs - https://docs.unity3d.com/ScriptReference/Application.RequestUserAuthorization.html is only for iOS… It seems the API was never unified. For Android, you want to use https://docs.unity3d.com/ScriptReference/Android.Permission.RequestUserPermission.html
UnityEngine.Android.Permission.RequestUserPermission only works after I restart the app. The first time (even if I granted the request), the permission (returned by UnityEngine.Android.Permission.HasUserAuthorizedPermission(PermissionName)) is false. Any idea??
Fangh:
Is there a way to know if the user has already authorized or not the permission on iOS ?
This docs says it only works on webplayer :
https://docs.unity3d.com/ScriptReference/Application.HasUserAuthorization.html
The docs might be outdated, did you try using this function on iOS?