Exemplo n.º 1
0
        public static bool HasPermission(Context context, ConstantsAndTypes.AppPermission permission)
        {
            if (GlobalData.ApplicationPermissions == null)
            {
                GlobalData.ApplicationPermissions = SetupDefaultPermissionList(context);
            }

            var thePermission = GlobalData.ApplicationPermissions.Find(perm => perm.ApplicationPermission == permission);

            return(thePermission != null);
        }
Exemplo n.º 2
0
        private void ShowPermissionRationale(ConstantsAndTypes.AppPermission permission)
        {
            try
            {
                if (permission == ConstantsAndTypes.AppPermission.SendSms)
                {
                    if (GlobalData.Settings.Find(setting => setting.SettingKey == "NagSendSms").SettingValue == "True")
                    {
                        return;
                    }
                }

                if (permission == ConstantsAndTypes.AppPermission.MakeCalls)
                {
                    if (GlobalData.Settings.Find(setting => setting.SettingKey == "NagMakeCalls").SettingValue == "True")
                    {
                        return;
                    }
                }

                AlertHelper alertHelper = new AlertHelper(this);

                string instanceId   = "";
                string alertTitle   = "";
                string alertMessage = "";

                if (permission == ConstantsAndTypes.AppPermission.SendSms)
                {
                    instanceId   = "sendSms";
                    alertTitle   = GetString(Resource.String.RequestPermissionSendSmsAlertTitle);
                    alertMessage = GetString(Resource.String.RequestPermissionSendSmsAlertMessage);
                }
                if (permission == ConstantsAndTypes.AppPermission.MakeCalls)
                {
                    instanceId   = "makeCalls";
                    alertTitle   = GetString(Resource.String.RequestPermissionMakeCallsAlertTitle);
                    alertMessage = GetString(Resource.String.RequestPermissionMakeCallsAlertMessage);
                }

                alertHelper.AlertIconResourceID  = Resource.Drawable.SymbolInformation;
                alertHelper.AlertMessage         = alertMessage;
                alertHelper.AlertNegativeCaption = GetString(Resource.String.ButtonNoCaption);
                alertHelper.AlertPositiveCaption = GetString(Resource.String.ButtonYesCaption);
                alertHelper.AlertTitle           = alertTitle;
                alertHelper.InstanceId           = instanceId;
                alertHelper.ShowAlert();
            }
            catch (Exception e)
            {
                Log.Error(TAG, "ShowPermissionRationale: Exception - " + e.Message);
                ErrorDisplay.ShowErrorAlert(this, e, GetString(Resource.String.ErrorMicPermissionShowRationalAlert), "HelpNowActivity.ShowPermissionRationale");
            }
        }
Exemplo n.º 3
0
 private void CheckPermission(ConstantsAndTypes.AppPermission permission)
 {
     try
     {
         if (!(PermissionsHelper.HasPermission(this, permission) && PermissionsHelper.PermissionGranted(this, permission)))
         {
             AttemptPermissionRequest(permission);
         }
     }
     catch (Exception e)
     {
         Log.Error(TAG, "CheckPermission: Exception - " + e.Message);
         ErrorDisplay.ShowErrorAlert(this, e, "Checking Microphone permission", "SafetyActivity.CheckPermission");
     }
 }
Exemplo n.º 4
0
        public static int GetRequestCodeForPermission(Context context, ConstantsAndTypes.AppPermission permission)
        {
            if (GlobalData.ApplicationPermissions == null)
            {
                GlobalData.ApplicationPermissions = SetupDefaultPermissionList(context);
            }

            var thePermission = GlobalData.ApplicationPermissions.Find(perm => perm.ApplicationPermission == permission);

            if (thePermission != null)
            {
                return(thePermission.PermissionType);
            }

            return(-1);
        }
Exemplo n.º 5
0
        public static bool PermissionGranted(Context context, ConstantsAndTypes.AppPermission permission)
        {
            if (GlobalData.ApplicationPermissions == null)
            {
                GlobalData.ApplicationPermissions = SetupDefaultPermissionList(context);
            }

            var thePermission = GlobalData.ApplicationPermissions.Find(perm => perm.ApplicationPermission == permission);

            if (thePermission != null)
            {
                return(thePermission.PermissionGranted == Permission.Granted);
            }

            return(false);
        }
Exemplo n.º 6
0
        //Calling activities MUST override OnRequestPermissionsResult
        public static void RequestApplicationPermission(Activity activity, ConstantsAndTypes.AppPermission permission)
        {
            if (GlobalData.ApplicationPermissions == null)
            {
                GlobalData.ApplicationPermissions = SetupDefaultPermissionList(activity);
            }

            var thePermission = GlobalData.ApplicationPermissions.Find(perm => perm.ApplicationPermission == permission);

            string[] permissionString = new string[1];
            permissionString = StringHelper.GetPermissionStringForEnum(permission);

            if (thePermission != null && permissionString != null)
            {
                ActivityCompat.RequestPermissions(activity, permissionString, thePermission.PermissionType);
            }
        }
Exemplo n.º 7
0
        public static bool ShouldShowPermissionRationale(Activity activity, ConstantsAndTypes.AppPermission permission)
        {
            if (GlobalData.ApplicationPermissions == null)
            {
                GlobalData.ApplicationPermissions = SetupDefaultPermissionList(activity);
            }

            var thePermission = GlobalData.ApplicationPermissions.Find(perm => perm.ApplicationPermission == permission);

            string[] permissionString = new string[1];
            permissionString = StringHelper.GetPermissionStringForEnum(permission);

            if (thePermission != null && permissionString != null)
            {
                return(ActivityCompat.ShouldShowRequestPermissionRationale(activity, permissionString[0]));
            }

            return(false);
        }
Exemplo n.º 8
0
 public void AttemptPermissionRequest(ConstantsAndTypes.AppPermission permission)
 {
     try
     {
         if (PermissionsHelper.ShouldShowPermissionRationale(this, permission))
         {
             ShowPermissionRationale(permission);
             return;
         }
         else
         {
             //just request the permission
             PermissionsHelper.RequestApplicationPermission(this, permission);
             return;
         }
     }
     catch (Exception e)
     {
         Log.Error(TAG, "AttemptPermissionRequest: Exception - " + e.Message);
         ErrorDisplay.ShowErrorAlert(this, e, "Attempting permission request", "HelpNowActivity.AttemptPermissionRequest");
     }
 }