我已经构建了一个自定义的AndroidX86版本,以进行质量检查,其中TelephonyManager.class
正在读取 / storage / emulated / 0 / MY_DIR 中文件的内容。问题是当尝试从文件读取"Permission Denied"
错误时发生。谁能告诉我如何授予TelephonyManager.class
读取文件的权限?
预先谢谢你!
答案 0 :(得分:0)
在AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
活动
if (!checkPermission()) {
requestPermission();
} else {
// you have access to the phone state continue your work
}
public boolean checkPermission(String type) {
int result = ContextCompat.checkSelfPermission(this, WRITE_EXTERNAL_STORAGE);
return result == PackageManager.PERMISSION_GRANTED;
}
public void requestPermission(String type) {
ActivityCompat.requestPermissions(this, new String[]{ READ_PHONE_STATE}, REQUEST_CODE);
}