AndroidPermission.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using SC.XR.Unity;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.Android;
  7. public class AndroidPermission : AndroidPluginBase
  8. {
  9. private static AndroidPermission Instant;
  10. public static AndroidPermission getInstant {
  11. get {
  12. if(Instant == null) {
  13. Instant = new AndroidPermission();
  14. }
  15. return Instant;
  16. }
  17. }
  18. private AndroidJavaClass AndroidPermissionClass { get; set; }
  19. private AndroidJavaObject AndroidPermissionObject { get; set; }
  20. private AndroidPermission() {
  21. AndroidPermissionClass = GetAndroidJavaClass("com.example.libpermission.PermissionRequest");
  22. AndroidPermissionObject = ClassFunctionCallStatic<AndroidJavaObject>(AndroidPermissionClass, "getInstant", CurrentActivity);
  23. }
  24. string[] permissionArray;
  25. public void GetPermission(List<string> permissionList) {
  26. if (permissionList == null || permissionList.Count == 0) {
  27. return;
  28. }
  29. permissionArray = permissionList.ToArray();
  30. ObjectFunctionCall2(AndroidPermissionObject, "RequestPermission", permissionArray);
  31. }
  32. [Obsolete("Please Use PermissionRequest.getInstanct.GetPerssion(Permission.XXX)")]
  33. public void GetPermission(bool Camera = true, bool ExternalStorageRead = true, bool ExternalStorageWrite = true, bool Microphone = false, bool FineLocation = false, bool CoarseLocation = false) {
  34. List<string> permissionList = new List<string>();
  35. if (Camera) {
  36. PermissionRequest.getInstance.GetPerssion(Permission.Camera);
  37. }
  38. if (ExternalStorageRead) {
  39. PermissionRequest.getInstance.GetPerssion(Permission.ExternalStorageRead);
  40. }
  41. if (ExternalStorageWrite) {
  42. PermissionRequest.getInstance.GetPerssion(Permission.ExternalStorageWrite);
  43. }
  44. if (Microphone) {
  45. PermissionRequest.getInstance.GetPerssion(Permission.Microphone);
  46. }
  47. if (FineLocation) {
  48. PermissionRequest.getInstance.GetPerssion(Permission.FineLocation);
  49. }
  50. if (CoarseLocation) {
  51. PermissionRequest.getInstance.GetPerssion(Permission.CoarseLocation);
  52. }
  53. }
  54. }