Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Android Permissions Not Being Requested

Discussion in 'Scripting' started by taylorbrown2686, Jul 2, 2020.

  1. taylorbrown2686

    taylorbrown2686

    Joined:
    Jun 14, 2019
    Posts:
    27
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Android;
    5.  
    6. public class AskForPermissions : MonoBehaviour
    7. {
    8.  
    9.     void Start() {
    10.       if (!Permission.HasUserAuthorizedPermission("android.permission.CAMERA")) {
    11.         Permission.RequestUserPermission("android.permission.CAMERA");
    12.       }
    13.       if (!Permission.HasUserAuthorizedPermission("android.permission.READ_EXTERNAL_STORAGE")) {
    14.         Permission.RequestUserPermission("android.permission.READ_EXTERNAL_STORAGE");
    15.       }
    16.       if (!Permission.HasUserAuthorizedPermission("android.permission.WRITE_EXTERNAL_STORAGE")) {
    17.         Permission.RequestUserPermission("android.permission.WRITE_EXTERNAL_STORAGE");
    18.       }
    19.     }
    20. }
    21.  
    From what the docs have told me, there should be nothing wrong with the following code. I have seen many people with similar problems, but no solution has worked for me. Am I missing something? How can I request multiple permissions on runtime of the app?
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
  3. taylorbrown2686

    taylorbrown2686

    Joined:
    Jun 14, 2019
    Posts:
    27
    Well, it didn't work entirely on it's own, but some code refactoring got it to do the job for me, thank you!