How to grant permission to the TelephoneManager.class to read a file in Android-X86

103 Views Asked by At

I've built a custom AndroidX86 build for QA purposes where the TelephonyManager.class is reading the content of a file located in /storage/emulated/0/MY_DIR. The problem is when attempting to read from file a "Permission Denied" error occurs. Can anyone please tell me how can I grant permission to the TelephonyManager.class to read a file? Thank you in advance!

1

There are 1 best solutions below

1
On

in AndroidManifest.xml

    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>   

in Activity

 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);
}