Example usage for android.app Activity shouldShowRequestPermissionRationale

List of usage examples for android.app Activity shouldShowRequestPermissionRationale

Introduction

In this page you can find the example usage for android.app Activity shouldShowRequestPermissionRationale.

Prototype

public boolean shouldShowRequestPermissionRationale(@NonNull String permission) 

Source Link

Document

Gets whether you should show UI with rationale for requesting a permission.

Usage

From source file:com.mobiuso.argo.ARModule.CameraSurface.java

@SuppressWarnings("deprecation")
public CameraSurface(Context context) {
    super(context);

    Log.i(TAG, "CameraSurface(): ctor called");
    Activity activityRef = (Activity) context;

    try {//from www  .  j  av  a2s .c  o  m
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activityRef.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CameraSurface(): must ask user for camera access permission");
                activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        ARMovieActivity.REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.
}

From source file:org.artoolkit.ar.samples.nftSimple.CameraSurface.java

@SuppressWarnings("deprecation")
public CameraSurface(Context context) {
    super(context);
    Log.i(TAG, "CameraSurface(): ctor called");
    Activity activityRef = (Activity) context;

    try {/*  w  w w . j  a  v  a2s . c  om*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activityRef.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CameraSurface(): must ask user for camera access permission");
                activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        nftSimpleActivity.REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.
}

From source file:org.artoolkit.ar.utils.calib_optical.CameraSurface.java

@SuppressWarnings("deprecation")
public CameraSurface(Context context) {
    super(context);

    Log.i(TAG, "CameraSurface(): ctor called");
    Activity activityRef = (Activity) context;

    try {/*from w  ww.j  av a  2 s .c o m*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activityRef.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CameraSurface(): must ask user for camera access permission");
                activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        calib_optical_Activity.REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.
}

From source file:org.artoolkit.ar.base.camera.CaptureCameraPreview.java

/**
 * Constructor takes a {@link CameraEventListener} which will be called on
 * to handle camera related events.//w w  w . j  a  va2 s .c  o  m
 *
 * @param cel CameraEventListener to use. Can be null.
 */
@SuppressWarnings("deprecation")
public CaptureCameraPreview(Activity activity, CameraEventListener cel) {
    super(activity);

    Log.i(TAG, "CaptureCameraPreview(): ctor called");
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activity,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activity.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activity.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CaptureCameraPreview(): must ask user for camera access permission");
                activity.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CaptureCameraPreview(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.

    setCameraEventListener(cel);
}

From source file:org.telegram.ui.DialogsActivity.java

@Override
public void onResume() {
    super.onResume();
    if (dialogsAdapter != null) {
        dialogsAdapter.notifyDataSetChanged();
    }//from w  w w. j av  a  2s. co  m
    if (dialogsSearchAdapter != null) {
        dialogsSearchAdapter.notifyDataSetChanged();
    }
    if (checkPermission && !onlySelect && Build.VERSION.SDK_INT >= 23) {
        Activity activity = getParentActivity();
        if (activity != null) {
            checkPermission = false;
            if (activity
                    .checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED
                    || activity.checkSelfPermission(
                            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                if (activity.shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setMessage(
                            LocaleController.getString("PermissionContacts", R.string.PermissionContacts));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    showDialog(permissionDialog = builder.create());
                } else if (activity
                        .shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setMessage(
                            LocaleController.getString("PermissionStorage", R.string.PermissionStorage));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    showDialog(permissionDialog = builder.create());
                } else {
                    askForPermissons();
                }
            }
        }
    }
}

From source file:org.cafemember.ui.DialogsActivity.java

@Override
public void onResume() {
    super.onResume();
    if (Defaults.getInstance().getMyToken().equals("")) {
        Commands.login(UserConfig.getCurrentUser().phone, new OnResponseReadyListener() {
            @Override/*from  w  ww .j a v a  2s.co  m*/
            public void OnResponseReady(boolean error, JSONObject data, String message) {
                Commands.loadCoins(new OnCoinsReady() {
                    @Override
                    public void onCoins(int viewCoinsAmount, int joinCoinsAmount) {
                        Log.e("COIN", joinCoinsAmount + "");
                        ApplicationLoader.setJoinCoins(joinCoinsAmount, true);
                    }
                });
            }
        });
    } else {
        Commands.loadCoins(new OnCoinsReady() {
            @Override
            public void onCoins(int viewCoinsAmount, int joinCoinsAmount) {
                Log.e("COIN", joinCoinsAmount + "");
                ApplicationLoader.setJoinCoins(joinCoinsAmount, true);
            }
        });
    }

    if (dialogsAdapter != null) {
        dialogsAdapter.notifyDataSetChanged();
    }
    if (dialogsSearchAdapter != null) {
        dialogsSearchAdapter.notifyDataSetChanged();
    }
    if (checkPermission && !onlySelect && Build.VERSION.SDK_INT >= 23) {
        Activity activity = getParentActivity();
        if (activity != null) {
            checkPermission = false;
            if (activity
                    .checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED
                    || activity.checkSelfPermission(
                            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                if (activity.shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setMessage(
                            LocaleController.getString("PermissionContacts", R.string.PermissionContacts));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    showDialog(permissionDialog = builder.create());
                } else if (activity
                        .shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setMessage(
                            LocaleController.getString("PermissionStorage", R.string.PermissionStorage));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    showDialog(permissionDialog = builder.create());
                } else {
                    askForPermissons();
                }
            }
        }
    }
}

From source file:kr.wdream.ui.DialogsActivity.java

@Override
public void onResume() {
    super.onResume();
    if (LaunchActivity.contactsAdapter != null) {
        LaunchActivity.contactsAdapter.notifyDataSetChanged();
    }//from  w w w  .j a  va 2 s  . c o  m

    if (dialogsAdapter != null) {
        dialogsAdapter.notifyDataSetChanged();
    }
    if (dialogsSearchAdapter != null) {
        dialogsSearchAdapter.notifyDataSetChanged();
    }
    if (checkPermission && !onlySelect && Build.VERSION.SDK_INT >= 23) {
        Activity activity = getParentActivity();
        if (activity != null) {
            checkPermission = false;
            if (activity
                    .checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED
                    || activity.checkSelfPermission(
                            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                if (activity.shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                    builder.setTitle(
                            LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName));
                    builder.setMessage(LocaleController.getString("PermissionContacts",
                            kr.wdream.storyshop.R.string.PermissionContacts));
                    builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK),
                            null);
                    showDialog(permissionDialog = builder.create());
                } else if (activity
                        .shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                    builder.setTitle(
                            LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName));
                    builder.setMessage(LocaleController.getString("PermissionStorage",
                            kr.wdream.storyshop.R.string.PermissionStorage));
                    builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK),
                            null);
                    showDialog(permissionDialog = builder.create());
                } else {
                    askForPermissons();
                }
            }
        }
    }
}