Android 6(API 레벨 23) 이상에서는 Android.Permission API를 사용하여 일반적으로 필요한 시스템 기능(예: 카메라, 마이크, 위치 정보)을 사용하기 위한 권한을 애플리케이션이 시동될 때가 아닌 필요한 시점에 사용하도록 요청할 수 있습니다. 개별 권한을 필요할 때 요청할 수 있으며, 사용자에게 이러한 권한을 요청하는 이유를 설명하는 메시지를 표시할 수 있습니다.
일반적으로 Android에서는 사용자에게 앱이 시작 시 필요로 하는 권한의 목록을 표시하되, 이러한 권한이 사용되는 이유나 컨텍스트에 대한 설명은 제공하지 않습니다. 이는 혼란을 주어 일부 사용자가 애플리케이션의 작동에 필수적인 권한을 허용하지 않는 결과를 초래할 수 있습니다.
Google의 권한 요청 가이드라인에 따르면, 사용자가 최초로 권한 요청을 거부할 때 이러한 권한을 요청하는 이유를 표시하고 요청을 다시 수락할 기회를 제공하는 방법이 권장됩니다.
Permission.HasUserAuthorizedPermission 함수를 사용하여 사용자가 권한을 승인했는지 확인할 수 있습니다. 권한이 승인되지 않았다면 앱에서 이러한 권한을 필요로 하는 이유를 설명하고 권한을 다시 요청할 수 있습니다. 사용자의 승인을 받으면 Permission.RequestUserPermission을 호출하여 권한을 다시 요청합니다. 이 함수를 호출하면 Android는 사용자가 권한을 승인하거나 거부할 수 있는 시스템 권한 다이얼로그를 엽니다.
사용자가 계속해서 권한 요청을 거부하면 앱에서 관련 기능을 비활성화하거나, 앱이 해당 기능 없이 작동하지 않는 경우 이러한 사실을 사용자에게 알려야 합니다. 단, 사용자가 이전에 시스템 권한 다이얼로그에서 “다시 묻지 않기” 옵션을 선택한 경우, RequestUserPermission()
은 시스템 다이얼로그를 열지 않습니다. 이 경우, 사용자는 애플리케이션 권한 설정으로 이동하여 권한을 수동으로 켜야 합니다.
Android 매니페스트에 unityplayer.SkipPermissionsDialog
메타 데이터를 추가하여 앱이 시동될 때 일반적으로 표시되는 권한 다이얼로그를 숨길 수 있습니다. 이 경우, 보호된 기능에 대한 액세스를 얻으려면 적절한 시점에 Permission.RequestUserPermission을 호출해야 합니다. 자세한 내용은 Android 매니페스트를 참조하십시오.
Android 권한 요청에 대한 자세한 내용은 Android 개발자 가이드의 앱 권한 베스트 프랙티스를 참조하십시오.
다음의 예제 코드는 특정 권한이 허용되었는지 확인하고, 사용자가 권한을 거부한 경우 다이얼로그를 표시하는 방법을 나타냅니다.
using UnityEngine;
# if PLATFORM_ANDROID
using UnityEngine.Android;
# endif
public class MicrophoneTest : MonoBehaviour
{
GameObject dialog = null;
void Start ()
{
#if PLATFORM_ANDROID
if (!Permission.HasUserAuthorizedPermission(Permission.Microphone))
{
Permission.RequestUserPermission(Permission.Microphone);
dialog = new GameObject();
}
#endif
}
void OnGUI ()
{
#if PLATFORM_ANDROID
if (!Permission.HasUserAuthorizedPermission(Permission.Microphone))
{
// The user denied permission to use the microphone.
// Display a message explaining why you need it with Yes/No buttons.
// If the user says yes then present the request again
// Display a dialog here.
dialog.AddComponent<PermissionsRationaleDialog>();
return;
}
else if (dialog != null)
{
Destroy(dialog);
}
#endif
// Now you can do things with the microphone
}
}
using UnityEngine;
# if PLATFORM_ANDROID
using UnityEngine.Android;
# endif
public class PermissionsRationaleDialog : MonoBehaviour
{
const int kDialogWidth = 300;
const int kDialogHeight = 100;
private bool windowOpen = true;
void DoMyWindow(int windowID)
{
GUI.Label(new Rect(10, 20, kDialogWidth - 20, kDialogHeight - 50), "Please let me use the microphone.");
GUI.Button(new Rect(10, kDialogHeight - 30, 100, 20), "No");
if (GUI.Button(new Rect(kDialogWidth - 110, kDialogHeight - 30, 100, 20), "Yes"))
{
#if PLATFORM_ANDROID
Permission.RequestUserPermission(Permission.Microphone);
#endif
windowOpen = false;
}
}
void OnGUI ()
{
if (windowOpen)
{
Rect rect = new Rect((Screen.width / 2) - (kDialogWidth / 2), (Screen.height / 2) - (kDialogHeight / 2), kDialogWidth, kDialogHeight);
GUI.ModalWindow(0, rect, DoMyWindow, "Permissions Request Dialog");
}
}
}
참고: 게임 오브젝트에 MicrophoneTest
를 컴포넌트로 추가하되, PermissionsRationaleDialog
는 컴포넌트로 추가하지 마십시오. MicrophoneTest
는 자동으로 게임 오브젝트를 생성하며 다이얼로그를 표시해야 할 때 PermissionsRationaleDialog
를 추가합니다. 또한 앱에서 마이크 사용 권한을 추가하려면 Unity용 Microphone 클래스를 사용해야 합니다.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.