1, Method 1
private static final int PERMISSION_REQUEST_CODE = 1; private String[]
mPermissions = {Manifest.permission.CAMERA}; /** * Application permission result return processing */ @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
Log.i("lgq","onRequestPermissionsResult ....."+requestCode); if (requestCode ==
PERMISSION_REQUEST_CODE) { boolean isAllGranted = true; for (int grant :
grantResults) { // Determine whether all permissions have been granted Log.i("lgq"," Application results ===="+grant); if (grant
!= PackageManager.PERMISSION_GRANTED) { isAllGranted = false; break; } } if
(isAllGranted) { // All permissions are granted // startCamera(); Log.i("lgq"," I agree kaiqil
..onRequestPermissionsResult..."); } else {// Prompt why permission is required Log.i("lgq"," No more kaiqil
..onRequestPermissionsResult..."); AlertDialog.Builder builder = new
AlertDialog.Builder(this); builder.setMessage(" Permission to take photos is required , Open again ? opposition ")
.setTitle(" Tips ") .setPositiveButton(" confirm ", new DialogInterface.OnClickListener()
{ @Override public void onClick(DialogInterface dialog, int which) {
ActivityCompat.requestPermissions(MainActivity.this, mPermissions,
PERMISSION_REQUEST_CODE); } }) .setNegativeButton(" cancel ", new
DialogInterface.OnClickListener() { @Override public void
onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } });
builder.create().show(); } } }
 

When you first click disable :

 

2, Method 2

1, Add dependency
//RxPermission Permission application implementation
'com.tbruyelle.rxpermissions2:rxpermissions:0.9.4@aar' //RxBinding
implementation 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
2, Application authority , Processing application results
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission
android:name="android.permission.CAMERA"/> /** * All required permission types */ private static
final String[] PERMISSIONS = {Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA}; /** *
Get permission dynamically */ public void getPermission() { RxPermissions rxPermissions = new
RxPermissions(MainActivity.this);
rxPermissions.request(PERMISSIONS).subscribe(new Consumer<Boolean>() {
@Override public void accept(Boolean granted) throws Exception { if(granted){
// Permission application successful Toast.makeText(MainActivity.this,"cg",Toast.LENGTH_SHORT).show();
}else{ // Permission application failed , Pop up to exit
Toast.makeText(MainActivity.this,"cg222",Toast.LENGTH_SHORT).show(); } } }); }
 

  Advanced method :
implementation 'com.yanzhenjie:permission:1.1.2' public void
checkPermission(){ // Judge whether you have camera permission first AndPermission.with(this) .requestCode(100)
.permission(Permission.CAMERA) .callback(listener)
.rationale(mRationaleListener) .start(); }
// After the user denies permission once , It is detected that the permission has been applied once when applying again , Allow developers to pop up to explain the purpose of permission application , Obtain the user's consent before applying for permission , Avoid the user's check and no more prompt , As a result, you cannot apply for permission again
private RationaleListener mRationaleListener = new RationaleListener() {
@Override public void showRequestPermissionRationale(int requestCode, final
Rationale rationale) { if(100==requestCode){ Log.i("lgq"," Refused ..."); } } };
// Camera permission monitoring PermissionListener listener = new PermissionListener() { @Override
public void onSucceed(int requestCode, @NonNull List<String> grantPermissions)
{ if(100==requestCode){// Turn on the camera Log.i("lgq"," Agreed ..."); } } @Override public
void onFailed(int requestCode, @NonNull List<String> deniedPermissions) {
if(100==requestCode){// camera AndPermission.defaultSettingDialog(MainActivity.this,
100) .setTitle(" Permission application failed ") .setMessage(" Basic camera permission required , Otherwise, you will not be able to use it normally , Please authorize in settings ")
.setPositiveButton(" good , Go to the settings ") .setNegativeButton("", new
DialogInterface.OnClickListener() { @Override public void
onClick(DialogInterface dialog, int which) { return; } }) .show(); } } };
 

Technology