//判断是否为android6.0系统版本,如果是,需要动态添加敏感权限
if (Build.VERSION.SDK_INT>=23){
checkPopedom();
}
private void checkPopedom(){
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
|| ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
|| ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED
|| ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED
|| ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
//申请 并设置回调相应吗
ActivityCompat.requestPermissions(ShouYeActivity.this,new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},1000);
}
}
//Android6.0申请权限的回调方法
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
// requestCode即所声明的权限获取码,checkPopedom传入
case 1000:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// 获取到权限,作相应处理
// init();
} else {
// 没有获取到权限,做特殊处理
// CustomToast.showToast(ShouYeActivity.this,"获取权限失败,请手动开启!");
}
break;
default:
break;
}
}
android6.0敏感权限动态申请
最新推荐文章于 2023-05-12 10:04:07 发布