public static void requestPermission()

in app/src/main/java/org/apache/fineract/utils/CheckSelfPermissionAndRequest.java [201:271]


    public static void requestPermission(final AppCompatActivity activity,
            final String permission,
            final int permissionRequestCode,
            final String dialogMessageRetry,
            final String messageNeverAskAgain,
            final String permissionDeniedStatus) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {

            // Show an explanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
            new MaterialDialog.Builder().init(activity)
                    .setTitle(R.string.dialog_permission_denied)
                    .setMessage(dialogMessageRetry)
                    .setPositiveButton(R.string.dialog_action_re_try,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    ActivityCompat.requestPermissions(activity, new
                                                    String[]{permission},
                                            permissionRequestCode);
                                }
                            })
                    .setNegativeButton(R.string.dialog_action_i_am_sure)
                    .createMaterialDialog()
                    .show();
        } else {

            //Requesting Permission, first time to the device.
            PreferencesHelper preferencesHelper = new PreferencesHelper(activity.
                    getApplicationContext());
            if (preferencesHelper.getBoolean(permissionDeniedStatus, true)) {
                preferencesHelper.putBoolean(permissionDeniedStatus, false);

                ActivityCompat.requestPermissions(activity, new String[]{permission},
                        permissionRequestCode);
            } else {
                //Requesting Permission, more the one time and opening the setting to change
                // the Permission in App Settings.
                new MaterialDialog.Builder().init(activity)
                        .setMessage(messageNeverAskAgain)
                        .setNegativeButton(R.string.dialog_action_cancel)
                        .setPositiveButton(R.string.dialog_action_app_settings,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        //Making the Intent to grant the permission
                                        Intent intent =
                                                new Intent(Settings
                                                        .ACTION_APPLICATION_DETAILS_SETTINGS);
                                        Uri uri = Uri.fromParts(activity.getResources().getString(
                                                R.string.package_name), activity.getPackageName()
                                                , null);
                                        intent.setData(uri);
                                        PackageManager pm = activity.getPackageManager();
                                        if (intent.resolveActivity(pm) != null) {
                                            activity.startActivityForResult(intent,
                                                    ConstantKeys.REQUEST_PERMISSION_SETTING);
                                        } else {
                                            Toast.makeText(activity, activity.getString(
                                                    R.string.msg_setting_activity_not_found)
                                                    , Toast.LENGTH_LONG).show();
                                        }
                                    }
                                })
                        .createMaterialDialog()
                        .show();
            }
        }
    }