Answer the question
In order to leave comments, you need to log in
How to get android app permission?
ActivityCompat.requestPermissions(MainActivity.this, new String[] {Manifest.permission.READ_CONTACTS}, REQUEST_CODE_PERMISSION_READ_CONTACTS);
int permissionStatus = ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_CONTACTS);
restext.setText(Integer.toString(permissionStatus));
Answer the question
In order to leave comments, you need to log in
just a guess. Is the REQUEST_CODE_PERMISSION_READ_CONTACTS variable declared?)
/**
* Id to identify a contacts permission request.
*/
private static final int REQUEST_CODE_PERMISSION_READ_CONTACTS = 0;
// Verify that all required contact permissions have been granted.
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) !=
PackageManager.PERMISSION_GRANTED ||
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CONTACTS) !=
PackageManager.PERMISSION_GRANTED) {
// Contacts permissions have not been granted.
Log.i(TAG, "Contact permissions has NOT been granted. Requesting permissions.");
requestContactsPermissions();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question