37 lines
873 B
C#
37 lines
873 B
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Android;
|
||
|
||
public class PermissionRequest : MonoBehaviour
|
||
{
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
requestPermission();
|
||
}
|
||
|
||
private void requestPermission()
|
||
{
|
||
if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead))
|
||
Permission.RequestUserPermission(Permission.ExternalStorageRead);
|
||
}
|
||
|
||
private void OnApplicationFocus(bool hasFocus)
|
||
{
|
||
if (hasFocus)
|
||
{
|
||
//Debug.Log("应用程序获得焦点(OnApplicationFocus)" + hasFocus);
|
||
}
|
||
else
|
||
{
|
||
//Debug.Log("应用程序失去焦点(OnApplicationFocus)" + hasFocus);
|
||
}
|
||
|
||
if (hasFocus)
|
||
{
|
||
requestPermission();
|
||
}
|
||
}
|
||
}
|