/// <summary>
        /// Example how to request for runtime permissions
        /// </summary>
        public void OnRequestPermissions()
        {
            // Don't forget to also add the permissions you need to manifest!
            var permissions = new[]
            {
                AGPermissions.WRITE_CONTACTS,
                AGPermissions.CALL_PHONE,
                AGPermissions.ACCESS_FINE_LOCATION,
                AGPermissions.READ_CALENDAR
            };

            // Filter permissions so we don't request already granted permissions,
            // otherwise if the user denies already granted permission the app will be killed
            var nonGrantedPermissions = permissions.ToList()
                                        .Where(x => !AGPermissions.IsPermissionGranted(x))
                                        .ToArray();

            if (nonGrantedPermissions.Length == 0)
            {
                var message = "User already granted all these permissions: " + string.Join(",", permissions);
                Debug.Log(message);
                AGUIMisc.ShowToast(message);
                return;
            }

            // Finally request permissions user has not granted yet and log the results
            AGPermissions.RequestPermissions(permissions, results =>
            {
                // Process results of requested permissions
                foreach (var result in results)
                {
                    string msg = string.Format("Permission [{0}] is [{1}], should show explanation?: {2}",
                                               result.Permission, result.Status, result.ShouldShowRequestPermissionRationale);
                    Debug.Log(msg);
                    AGUIMisc.ShowToast(msg);
                    if (result.Status == AGPermissions.PermissionStatus.Denied)
                    {
                        // User denied permission, now we need to find out if he clicked "Do not show again" checkbox
                        if (result.ShouldShowRequestPermissionRationale)
                        {
                            // User just denied permission, we can show explanation here and request permissions again
                            // or send user to settings to do so
                        }
                        else
                        {
                            // User checked "Do not show again" checkbox or permission can't be granted.
                            // We should continue with this permission denied
                        }
                    }
                }
            });
        }
示例#2
0
    private void RequestPermission(PermissionType type)
    {
#if PLATFORM_ANDROID
        switch (type)
        {
        case PermissionType.Camera:
            //RKLog.Log("Request Camera");
            Permission.RequestUserPermission(Permission.Camera);
            break;

        case PermissionType.Microphone:
            //RKLog.Log("Request Microphone");
            Permission.RequestUserPermission(Permission.Microphone);
            break;

        case PermissionType.Location:
            //RKLog.Log("Request Location");
            Permission.RequestUserPermission(Permission.CoarseLocation);
            break;

        case PermissionType.CalendarRead:
            //RKLog.Log("Request Calendar Read");
            AGPermissions.RequestPermissions(new string[] { AGPermissions.READ_CALENDAR }, results => { });
            break;

        case PermissionType.CalendarWrite:
            //RKLog.Log("Request Calendar Write");
            AGPermissions.RequestPermissions(new string[] { AGPermissions.WRITE_CALENDAR }, results => { });
            break;
        }
#endif

#if PLATFORM_IOS
        switch (type)
        {
        case PermissionType.Camera:
            Application.RequestUserAuthorization(UserAuthorization.WebCam);
            break;

        case PermissionType.Microphone:
            Application.RequestUserAuthorization(UserAuthorization.Microphone);
            break;

        case PermissionType.Location:
            //LocationController.Instance.StartTracking(() => Debug.LogError("tracking succesfull"), () => Debug.LogError("tracking failed"));
            break;
        }
#endif
    }