Android ultra clear 6.0 permission application andpermission

The specific implementation code of Android super clear 6.0 permission application andpermission is for your reference. The specific contents are as follows

preface

This is the framework I often use for the following reasons:

1. Clear thinking 2. Easy implementation

start

preparation

Guide Package

compile 'com.yanzhenjie:permission:1.0.7'

Then you can use it. It's simple

use

First step

findViewById(R.id.selectPic).setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        //检测权限
        AndPermission.with(MainActivity.this)
            .requestCode(202)
            .permission(Manifest.permission.CAMERA,Manifest.permission.WRITE_EXTERNAL_STORAGE)
            .callback(listener)
            .start();
      }
    });

Explanation:

1. Requestcode(): used for callback to determine where the request is made. 2. Permission(): just fill in the permission to be applied, but be sure to add 3. Callback(): fill in the callback object in androidmanifest.xml

When you click the button, you will automatically query whether you have permission. If not, the application box will pop up. If you have permission, you will directly go to the success method in the callback.

Step 2 callback object

//权限监听回调
  private PermissionListener listener = new PermissionListener() {
    @Override
    public void onSucceed(int requestCode,List<String> grantedPermissions) {
      // 权限申请成功回调。
      if (requestCode == 202) {
        //申请成功后的动作
      }

    }
    @Override
    public void onFailed(int requestCode,List<String> deniedPermissions) {
      // 权限申请失败回调。可提示
     }
  };

It's over. It's really simple.

The above is the whole content of this article. I hope it will help you in your study, and I hope you will support us a lot.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>