Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by sajoga · Oct 03, 2016 at 11:15 AM · cameramicrophonepermissionsgallery

Check device access permissions [iOS and Android]

Hi everyone!

I'm working on a project where the device Camera, Mic and Gallery are used. The problem comes if the user doesn't allow the app to access any of them. Is there any way to check device access permissions (both iOS and Android)?

Once checked, can I ask again for permissions (if previously denied)?

Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FatIgor · Nov 13, 2016 at 01:19 PM

@sajoga

An answer covering iOS.

https://forum.unity3d.com/threads/request-and-get-state-of-camera-permission.281858/

The final post in that thread tells you how to get the iOS permission state. Works, I've tried it. It only deals specifically with the camera, but would be easy to modify for the other states you wanted.

I don't know how to re-ask for permission, I just put up a dialog box telling them they will have to go to settings and give permission manually.

Not yet found a way of detecting on Android yet.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Conferno · May 28, 2019 at 10:02 PM 0
Share

How do you check, was permission denied or granted? I need this for the microphone on the iPhone.

avatar image
1

Answer by drewjosh · Nov 24, 2020 at 05:00 PM

For iOS I used the methods mentioned in the Unity docs here: https://docs.unity3d.com/ScriptReference/Application.RequestUserAuthorization.html

For Android also the methods from the docs: https://docs.unity3d.com/Manual/android-RequestingPermissions.html

I also needed to handle when permission was not granted. Here is my class (I need camera permission before I want to activate Vuforia Engine):

 using UnityEngine;
 using Vuforia;
 #if UNITY_ANDROID
 using UnityEngine.Android;
 #elif UNITY_IOS
 using UnityEngine.iOS;
 #endif
 
 public class CameraPermission : MonoBehaviour
 {
     public GameObject permissionUIparent;
     public GameObject explanationUI;
     public GameObject noAccessUI;
 
     bool isVuforiaInitializing = false;
     VuforiaBehaviour vuforiaBehaviour;
 
     void Awake()
     {
         vuforiaBehaviour = GameObject.Find("AR Camera").GetComponent<VuforiaBehaviour>();
     }
 
     void Start()
     {
         permissionUIparent.SetActive(true);
         explanationUI.SetActive(true);
         noAccessUI.SetActive(false);
     }
 
     void OnGUI()
     {
 #if PLATFORM_ANDROID
         if (!Permission.HasUserAuthorizedPermission(Permission.Camera))
         {
             // permission denied, no access should be visible, when activated when requested permission
             return;
         }
 #elif UNITY_IOS
         if (!Application.HasUserAuthorization(UserAuthorization.WebCam))
         {
             // permission denied, no access should be visible, when activated when requested permission
             return;
         }
 #endif
         // camera permission granted
 
         permissionUIparent.SetActive(false);
 
         if (!isVuforiaInitializing)
         {
             isVuforiaInitializing = true;
             ActivateVuforiaEngine();
         }
     }
 
     public void ActivateVuforiaEngine()
     {
         vuforiaBehaviour.enabled = true;
         VuforiaRuntime.Instance.InitVuforia();
     }
 
     public bool IsCameraPermissionGranted()
     {
 #if UNITY_ANDROID
         return Permission.HasUserAuthorizedPermission(Permission.Camera);
 #elif UNITY_IOS
         return Application.HasUserAuthorization(UserAuthorization.WebCam);
 #endif
     }
 
     public void RequestCameraPermission()
     {
         noAccessUI.SetActive(true); // so it will be visible if user doesn't give permission
 #if PLATFORM_ANDROID
         if (!Permission.HasUserAuthorizedPermission(Permission.Camera))
         {
             Permission.RequestUserPermission(Permission.Camera);
         }
 #elif UNITY_IOS
         if (!Application.HasUserAuthorization(UserAuthorization.WebCam))
         {
             Application.RequestUserAuthorization(UserAuthorization.WebCam);
         }
 #endif
     }
 
     public void ClickedNoAccessGranted()
     {
         noAccessUI.SetActive(true);
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by dansopanso · May 22, 2019 at 10:25 AM

Here is the Android Solution:

https://docs.unity3d.com/Manual/android-RequestingPermissions.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

80 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Check Camera Permissions for iOS and Android? 0 Answers

Screenshot is not saving to Gallery and folder 2 Answers

Could not open the camera with EmguCV 4.x on Android. 0 Answers

Get number of photos of Camera Roll ( iOs and Android ) 1 Answer

Can I use the microphone in Unity without bluetooth or broadcast_sticky permissions? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges