Cannot Resolve Symbol 'request_code_read_contacts
I'm trying to request permission to access the ringer using this: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ActivityCompat.checkSelfPermis
Solution 1:
If you copied the code above from answer in this topic
then just initialize it with 1
and add this method in your code
publicvoidonRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults){
switch (requestCode){
case REQUEST_CODE_READ_CONTACTS:
if(grantResults.length>0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
READ_CONTACTS_GRANTED = true;
}
}
if(READ_CONTACTS_GRANTED){
loadContacts();
}
else{
Toast.makeText(this, "Allow permission in settings", Toast.LENGTH_LONG).show();
}
}
Solution 2:
The value is a request code that you have to define yourself.
privatestaticfinalint REQUEST_CODE_READ_CONTACTS = 99; // Can be any value >= 0
You can use it to determine which permission request the user has responded to in the onRequestPermissionsResult()
callback by checking for the matching value.
publicvoidonRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults){
switch (requestCode) {
case REQUEST_CODE_READ_CONTACTS:
// Do your thingbreak;
case ...
}
}
Post a Comment for "Cannot Resolve Symbol 'request_code_read_contacts"