Merge pull request #72 from Unity-Technologies/fix-android13-rel-1-4
Make a separate sample version for 1.4.x series
This commit is contained in:
Коммит
20913e50f8
|
@ -2,6 +2,8 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using Unity.Notifications.Android;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Android;
|
||||
|
||||
namespace NotificationSamples.Android
|
||||
{
|
||||
|
@ -30,9 +32,34 @@ namespace NotificationSamples.Android
|
|||
|
||||
public IEnumerator RequestNotificationPermission()
|
||||
{
|
||||
var request = new PermissionRequest();
|
||||
while (request.Status == PermissionStatus.RequestPending)
|
||||
yield return null;
|
||||
const string notificationPermission = "android.permission.POST_NOTIFICATIONS";
|
||||
const int permissionRequiredSDK = 33;
|
||||
|
||||
using (var version = new AndroidJavaClass("android/os/Build$VERSION"))
|
||||
{
|
||||
var deviceSdk = version.GetStatic<int>("SDK_INT");
|
||||
if (deviceSdk < permissionRequiredSDK)
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (Permission.HasUserAuthorizedPermission(notificationPermission))
|
||||
yield break;
|
||||
|
||||
using (var playerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
|
||||
{
|
||||
using (var activity = playerClass.GetStatic<AndroidJavaObject>("currentActivity"))
|
||||
{
|
||||
using (var appInfo = activity.Call<AndroidJavaObject>("getApplicationInfo"))
|
||||
{
|
||||
var targetSdk = appInfo.Get<int>("targetSdkVersion");
|
||||
if (targetSdk < permissionRequiredSDK)
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Permission.RequestUserPermission(notificationPermission);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
Загрузка…
Ссылка в новой задаче