Z
Z
zyusifov112021-03-01 18:12:21
Java
zyusifov11, 2021-03-01 18:12:21

How to get android app permission?

ActivityCompat.requestPermissions(MainActivity.this, new String[] {Manifest.permission.READ_CONTACTS}, REQUEST_CODE_PERMISSION_READ_CONTACTS);

603d04270f856388177975.png

It also throws an error
int permissionStatus = ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_CONTACTS);
restext.setText(Integer.toString(permissionStatus));

Gives -1 is this normal?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Ryabykin, 2021-03-01
@geesoff

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;

and another piece
// 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();

}

Source

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question