您好,需要获取权限来读取许可的,您可以用该方法结合androidmanifest.xml获取到动态权限
private void requestPermissions() { //Android6.0以上设备设置动态权限
if (Build.VERSION.SDK_INT >= 23) {
// 检查是否拥有权限
String[] permissions = {
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.CHANGE_WIFI_STATE,
};
String permission = null;
int id = 0;
boolean isBreak = false;
int checkCallPhonePermission = 0;
for (int i = 0; i < permissions.length; i++) {
permission = permissions[i];
checkCallPhonePermission = checkSelfPermission(permission);
if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
requestPermissions(permissions, id);
isBreak = true;
break;
}
}
}
}
另外,看您的报错是空指针,建议build.gradle文件中compileSdkVersion与targetSdkVersion都改为28再运行