其他分享
首页 > 其他分享> > android检测SD卡读写权限详情,我浪费了自己职业生涯的黄金5年

android检测SD卡读写权限详情,我浪费了自己职业生涯的黄金5年

作者:互联网

requestPermission(HDCivilizationConstants.SD_CARD_REQUEST_CODE, “android.permission.WRITE_EXTERNAL_STORAGE”, new Runnable() {

@Override

public void run() {

//第一个Runnable

if (type==1){

FileUtils.saveBitmapPng(rectBitmap, pathList, 80);

}else{

try {

FileUtils.saveBitmapJPG(rectBitmap, pathList, 70);

} catch (ContentException e) {

e.printStackTrace();

}

}

}

}, new Runnable() {

@Override

public void run() {

//第二个Runnable

// UiUtils.getInstance().showToast(“请查看SD卡的读写权限”);

OKPopup.getInstance().showPopup(TakeCameraActivity.this, new OKPopup.BtnClickListener() {

@Override

public void btnOk() {

OKPopup.getInstance().dismissDialog();

}

}, false,

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

HDCivilizationConstants.SDCARD_PERMISSION);

}

});

2.调用上面的那个方法之后会跳转至这个方法(代码如下):

/**

*/

protected void requestPermission(int id, String permission, Runnable allowableRunnable, Runnable disallowableRunnable) {

if(allowableRunnable!=null){

allowablePermissionRunnables.put(id, allowableRunnable);

}

if (disallowableRunnable != null) {

disallowablePermissionRunnables.put(id, disallowableRunnable);

}

//api版本判断

if (Build.VERSION.SDK_INT >= 23) {

UiUtils.getInstance().showToast(“1”);

//减少是否拥有权限checkCallPhonePermission != PackageManager.PERMISSION_GRANTED

int checkCallPhonePermission = ContextCompat.checkSelfPermission(getApplicationContext(), permission);

if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {

UiUtils.getInstance().showToast(“2”);

//弹出对话框接收权限

ActivityCompat.requestPermissions(TakeCameraActivity.this, new String[]{permission}, id);

return;

} else {

UiUtils.getInstance().showToast(“3”);

if(allowableRunnable!=null){

allowableRunnable.run();

}

}

} else {

boolean result = PermissionChecker.checkSelfPermission(this, permission)

== PermissionChecker.PERMISSION_GRANTED;

if(!result){

UiUtils.getInstance().showToast(“4”);

//如果未授权

ActivityCompat.requestPermissions(TakeCameraActivity.this, new String[]{permission}, id);

}else{

UiUtils.getInstance().showToast(“5”);

if(allowableRunnable!=null){

allowableRunnable.run();

}

}

}

}

3.onRequestPermissionsResult方法是响应2中的方法之后执行。执行代码之后,开始执行Runnable中的代码程序。

@Override

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

super.onRequestPermissionsResult(requestCode, permissions, grantResults);

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

Runnable allowRun = allowablePermissionRunnables.get(requestCode);

if(allowRun!=null){

allowRun.run();

}

} else {

Runnable disallowRun = disallowablePermissionRunnables.get(requestCode);

if(disallowRun!=null){

disallowRun.run();

标签:allowableRunnable,Runnable,showToast,getInstance,permission,读写,android,id,SD
来源: https://blog.csdn.net/m0_65146105/article/details/122084236