android 处理权限被拒,java - 如何处理被拒绝的权限Android M(EasyPermissions) - 堆栈内存溢出...

如果您不想使用简单权限,请填写每个许可案例的完整说明

/**

* Case 1: User doesn't have permission

* Case 2: User has permission

*

* Case 3: User has never seen the permission Dialog

* Case 4: User has denied permission once but he din't clicked on "Never Show again" check box

* Case 5: User denied the permission and also clicked on the "Never Show again" check box.

* Case 6: User has allowed the permission

*

*/

public void handlePermission() {

if (ContextCompat.checkSelfPermission(MainActivity.this,

Manifest.permission.WRITE_EXTERNAL_STORAGE)

!= PackageManager.PERMISSION_GRANTED) {

// This is Case 1. Now we need to check further if permission was shown before or not

if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,

Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

// This is Case 4.

} else {

// This is Case 3. Request for permission here

}

} else {

// This is Case 2. You have permission now you can do anything related to it

}

}

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {

if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {

// This is Case 2 (Permission is now granted)

} else {

// This is Case 1 again as Permission is not granted by user

//Now further we check if used denied permanently or not

if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,

Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

// case 4 User has denied permission but not permanently

} else {

// case 5. Permission denied permanently.

// You can open Permission setting's page from here now.

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值