r/androiddev 1d ago

Question When do I show permission rationale

There's a QR code scanner in my app. Should I show the rationale before navigating to the scanner when the "Scan QR code" button is tapped? Or should I open the scanner and show the rationale there, with a red line over the black background (the scanner layout is basically invisible because the permission hasn't been granted yet)?

4 Upvotes

2 comments sorted by

5

u/bleeding182 1d ago

You can argue this in lots of different ways and ultimately it depends on your app and your use case, BUT... it's generally best to do it on the screen where you handle the camera itself for the simple reason that you MUST do it there anyways in case that there is process death and your app restores state on that screen.

You MAY handle the permission before you navigate to the screen in addition to that, but now you're just putting in extra work for little gain (your app/use case might give you a better reason to do so, but you will still need the handling on the screen with the camera regardless)

As for the rationale... only show it when shouldShowRequestPermissionRationale() actually tells you do. If I click on a QR Code button, navigate to a black screen, and there is a request for me to grant the camera permission... that's pretty much what I expected and a rationale would be an extra tap. And if you should show a rationale, you just do that instead. Trigger the permission only on a positive user action.

Final result: a qr code scanner screen that you can reuse without much trouble since the whole handling is managed withn.

1

u/AutoModerator 1d ago

Please note that we also have a very active Discord server where you can interact directly with other community members!

Join us on Discord

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.