Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

status === PermissionAndroid.RESULTS.GRANTED would be checking text against an object. #79

Open
maniac-tech opened this issue Jan 29, 2025 · 0 comments
Labels
good first issue Good for newcomers question Further information is requested

Comments

@maniac-tech
Copy link
Owner

          from what I have seen, status in this case would return 
{
  "android.permission.RECEIVE_SMS": "granted",
  "android.permission.READ_SMS": "denied"
}

so status === PermissionAndroid.RESULTS.GRANTED would be checking text against an object.

this can be rewritten as:

const status = await PermissionsAndroid.requestMultiple([
  PermissionsAndroid.PERMISSIONS.RECEIVE_SMS,
  PermissionsAndroid.PERMISSIONS.READ_SMS,
]);

const granted = PermissionsAndroid.RESULTS.GRANTED;
const denied = PermissionsAndroid.RESULTS.DENIED;
const neverAskAgain = PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN;

if (status[PermissionsAndroid.PERMISSIONS.RECEIVE_SMS] === granted &&
    status[PermissionsAndroid.PERMISSIONS.READ_SMS] === granted) {
  return true;
}

if ([status[PermissionsAndroid.PERMISSIONS.RECEIVE_SMS], status[PermissionsAndroid.PERMISSIONS.READ_SMS]].includes(denied)) {
  console.log("Read/Receive SMS permission denied by user.", status);
} else if ([status[PermissionsAndroid.PERMISSIONS.RECEIVE_SMS], status[PermissionsAndroid.PERMISSIONS.READ_SMS]].includes(neverAskAgain)) {
  console.log("Read/Receive SMS permission revoked by user.", status);
}

Originally posted by @alokpant in #76 (comment)

@maniac-tech maniac-tech added good first issue Good for newcomers question Further information is requested labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant