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