A
A
Artyom2021-08-06 19:23:38
Android
Artyom, 2021-08-06 19:23:38

Pop-ups not appearing on Android in Unity, how to fix?

I'm making a game in Unity and I need access to the files, but as you know, I have to get permission to do so. I'm trying to request it from the user through the code, but the pop-up window with the request (these often pop up in various android applications) simply does not appear.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Android;

public class Perm : MonoBehaviour
{
    readonly string[] _permissions = {Permission.ExternalStorageRead, Permission.ExternalStorageWrite};

    // Start is called before the first frame update
    void Awake()
    {
#if UNITY_ANDROID
        Permission.RequestUserPermission(Permission.ExternalStorageRead);
#endif
        RequestPermission();
        StartCoroutine(FckIt());
    }

    public void RequestPermission()
    {
        if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead))
            Permission.RequestUserPermissions(_permissions);
    }

    IEnumerator FckIt()
    {
        yield return new WaitForSeconds(10f);
        RequestPermission();
    }
}

Here you can see that the code repeats itself several times. These are my attempts to fix the code myself, but nothing helps. I studied the documentation in this question and repeated the material of several articles exactly, but nothing has changed. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom, 2021-08-07
Maidurov @sylniyduxom

After a long search, I found a solution. In order to solve this problem, you need to register all the necessary permissions in the AndroidManifest.xml file. Then at the start there will be a request, and a proposal will appear to allow the use of files

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question