/**
* 申请权限
*/
private void permission() {
if (Build.VERSION.SDK_INT >= 23) {
//检查权限
int readSDPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
if (readSDPermission != PackageManager.PERMISSION_GRANTED) {
Log.e("TAG", "" + readSDPermission);
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE},
123);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
Log.e("TAG", "" + requestCode);
if (requestCode == 123) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.e("TAG", "权限申请成功!");
} else {
Log.e("TAG", "权限申请失败!");
// Permission Denied
}
return;
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
6.0申请权限的方法
最新推荐文章于 2021-05-31 01:05:21 发布