示例#1
0
 private void HandleMicPermission()
 {
     if (!(PermissionsHelper.HasPermission(Activity, ConstantsAndTypes.AppPermission.UseMicrophone) && PermissionsHelper.PermissionGranted(Activity, ConstantsAndTypes.AppPermission.UseMicrophone)))
     {
         if (_speakAffirmation != null)
         {
             _speakAffirmation.SetImageResource(Resource.Drawable.micgreyscale);
             _speakAffirmation.Enabled = false;
         }
     }
 }
 private void CheckMicPermission()
 {
     try
     {
         if (!(PermissionsHelper.HasPermission(this, ConstantsAndTypes.AppPermission.UseMicrophone) && PermissionsHelper.PermissionGranted(this, ConstantsAndTypes.AppPermission.UseMicrophone)))
         {
             AttemptPermissionRequest();
         }
     }
     catch (Exception e)
     {
         Log.Error(TAG, "CheckMicPermission: Exception - " + e.Message);
         ErrorDisplay.ShowErrorAlert(this, e, "Checking Microphone permission", "StructuredPlanRelationshipsDialogActivity.CheckMicPermission");
     }
 }
 private void CheckMicPermission()
 {
     try
     {
         if (!(PermissionsHelper.HasPermission(Activity, ConstantsAndTypes.AppPermission.UseMicrophone) && PermissionsHelper.PermissionGranted(Activity, ConstantsAndTypes.AppPermission.UseMicrophone)))
         {
             Toast.MakeText(Activity, Resource.String.MicrophonePermissionDenialToast, ToastLength.Short).Show();
             if (_recordAudioButton != null)
             {
                 _recordAudioButton.Enabled = false;
             }
         }
     }
     catch (Exception e)
     {
         Log.Error(TAG, "CheckMicPermission: Exception - " + e.Message);
         ErrorDisplay.ShowErrorAlert(Activity, e, "Checking Microphone permission", "VoiceRecordingDialogFragment.CheckMicPermission");
     }
 }
 public void AttemptPermissionRequest()
 {
     try
     {
         if (PermissionsHelper.ShouldShowPermissionRationale(this, ConstantsAndTypes.AppPermission.UseMicrophone))
         {
             ShowPermissionRationale();
             return;
         }
         else
         {
             //just request the permission
             PermissionsHelper.RequestApplicationPermission(this, ConstantsAndTypes.AppPermission.UseMicrophone);
             return;
         }
     }
     catch (Exception e)
     {
         Log.Error(TAG, "AttemptPermissionRequest: Exception - " + e.Message);
         ErrorDisplay.ShowErrorAlert(this, e, "Attempting permission request", "StructuredPlanRelationshipsDialogActivity.AttemptPermissionRequest");
     }
 }
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
        {
            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);

            try
            {
                if (requestCode == ConstantsAndTypes.REQUEST_CODE_PERMISSION_USE_MICROPHONE)
                {
                    if (grantResults.Length > 0 && grantResults[0] == Permission.Granted)
                    {
                        //now update the global permission
                        if (GlobalData.ApplicationPermissions == null)
                        {
                            //if null then we can go get permissions
                            PermissionsHelper.SetupDefaultPermissionList(this);
                        }
                        else
                        {
                            //we need to update the existing permission
                            if (PermissionsHelper.HasPermission(this, ConstantsAndTypes.AppPermission.UseMicrophone))
                            {
                                GlobalData.ApplicationPermissions.Find(perm => perm.ApplicationPermission == ConstantsAndTypes.AppPermission.UseMicrophone).PermissionGranted = Permission.Granted;
                            }
                        }
                        PermissionResultUpdate(Permission.Granted);
                    }
                    else
                    {
                        PermissionResultUpdate(Permission.Denied);
                        Toast.MakeText(this, Resource.String.MicrophonePermissionDenialToast, ToastLength.Short).Show();
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(TAG, "OnRequestPermissionsResult: Exception - " + e.Message);
                ErrorDisplay.ShowErrorAlert(this, e, "Processing permission result", "StructuredPlanRelationshipsDialogActivity.OnRequestPermissionsResult");
            }
        }
        private void ShowPermissionRationale()
        {
            try
            {
                if (GlobalData.Settings.Find(setting => setting.SettingKey == "NagMic").SettingValue == "True")
                {
                    if (!(PermissionsHelper.HasPermission(this, ConstantsAndTypes.AppPermission.UseMicrophone) && PermissionsHelper.PermissionGranted(this, ConstantsAndTypes.AppPermission.UseMicrophone) == true))
                    {
                        PermissionResultUpdate(Permission.Denied);
                        Toast.MakeText(this, Resource.String.MicrophonePermissionDenialToast, ToastLength.Short).Show();
                    }
                    return;
                }

                AlertHelper alertHelper = new AlertHelper(this);

                alertHelper.AlertIconResourceID  = Resource.Drawable.SymbolInformation;
                alertHelper.AlertMessage         = GetString(Resource.String.RequestPermissionUseMicrophoneAlertMessage);
                alertHelper.AlertNegativeCaption = GetString(Resource.String.ButtonNoCaption);
                alertHelper.AlertPositiveCaption = GetString(Resource.String.ButtonYesCaption);
                alertHelper.AlertTitle           = GetString(Resource.String.RequestPermissionUseMicrophoneAlertTitle);
                alertHelper.InstanceId           = "useMic";
                alertHelper.ShowAlert();
            }
            catch (Exception e)
            {
                Log.Error(TAG, "ShowPermissionRationale: Exception - " + e.Message);
                ErrorDisplay.ShowErrorAlert(this, e, GetString(Resource.String.ErrorMicPermissionShowRationalAlert), "StructuredPlanRelationshipsDialogActivity.ShowPermissionRationale");
            }
        }