Is it possible to ask repeated prompt to the user,when the user provides deny in the permission(READ_PHONE_STATE) request pop up raised by shouldShowRequestPermissionRationale().
Once I Click on deny the prompt gets exited and my objective is to make him click only Allow.Is this achievable in android 6.0 Version ?
No, if the user wants to Deny permission they will always have that option. Its up to the developer to deal with that situation.
shouldShowRequestPermissionRationale is just a hint for you, you can choose the ignore the method's return value, or choose not to call that method at all.
If you have a permission you must have for the app to function properly, you should pop a dialog explaining this in simple language to the user, and keep asking for the permission until (a) the user gives you the permission, or (b) the user decides to uninstall the app.
Related
Due to some compliance, We are only allowed to take respective permission each time when user use that feature.
Obvious Scenario
Required Scenario
The short answer is, you can't.
As android documentation puts:
When your app calls requestPermissions(), the system shows a standard dialog box to the user. Your app cannot configure or alter that dialog box. If you need to provide any information or explanation to the user, you should do that before you call requestPermissions(), as described in "Explain why the app needs permissions".
So, there is no way to change dialog for the permission.
You can find more detailed information here: http://developer.android.com/training/permissions/requesting.html
There's no way to do that. But what you can do is use checkSelfPermission to see if you've already been granted that permission, and if so pop up a custom dialog to ensure it's still ok. Obviously the OS can't enforce that, but you can.
User can cancel a permission request by hitting the "Back" button. And since Android 11, user can also clicking on the outside of the permission dialog to cancel. When a permission is canceled, the permission is not granted, and shouldShowPermissionRationale() will return false, which means app can call requestPermissions() again.
When user choose "Don't ask again", or deny twice for a permission in Android 11, shouldShowPermissionRationale() will also return false. But how can I distinguish "Don't ask again" from the "Canceled" state?
I need to distinguish these two states is because that if user canceled a permission before, I know that I still have the chance to prompt the system permission dialog to them. But if user choose not to ask for a permission again, I need to guide them to the app info page to grant the permission manually.
It's not a direct solution to this problem because there appears to be no way to get that.
However, I have realised that there is a method where Android will tell us if we need to show RationaleDialog to our user without any work from our end (before I was under impression we need to keep track of this ourselves).
Just call activity.shouldShowRequestPermissionRationale(permission) and it will take care of all back calls itself.
My app must have Camera and Audio access without being requested each time (I don't want to get into details, but trust me on this one).
Is there a way to know on Android 11+ if the user clicked "Only this time" on either Camera or Audio permission?
You cannot say, when the user will disable the permissions given to your app.
If you want to have the permissions always (irrespective of when you actually gonna need it), ask the user to give the permission at the launch of your app. Other than this, you cannot stop the user to disable the permissions later.
Kind of like:
if (isPermissionGiven){
//Permission given, continue...
} else {
//Permisson not given, ask for permission...
}
By this you would be able to do your work unless you are doing any work to access the user's camera in background without the user's consent which is not Legitimate.
I couldn't find any information about what happens when the user disables an app's permission while the app is running.
Is the application re-initilized?
I saw that in some apps if a Dialog or BottomSheet is open while I disable the permission, the dialog is no longer displayed when I return to the app.
Can anyone explain what happens in-detail when a permission is denied at runtime? Or does anyone have some useful links for me?
I would be especially interested in which lifecycle events are called when returning to the app.
When a previously granted permission is revoked through settings, the app is force stopped. You can see this by watching your app in the debugger. The app process is marked DEAD as soon as the permission is revoked.
Returning to the app will launch it from the main activity. I've never really looked into why this happens, but I assume it's because when a granted permission is revoked, the user could be deep into the app at a place where it is assumed the permission is granted. When the permission is revoked, there's no way to know if the screen they are currently in is even valid anymore.
Upon returning to the app, the app's state is restored and your current activity will be restarted, similar to a configuration change. If the activity you are in assumes a certain permission is granted, you should probably check that permission again in onCreate() to make sure you have it.
Simply put, That depends on what the app is trying to do when it needs permission.
For example: If we live in a country that requires you to be an adult to watch any video on YouTube, nothing will work with Location permissions denied
Another example: If you want to take photos using your phone via an app, the Camera permission should be permitted.
Under some circumstances, just part functions of app can not be used, but at an Extreme case, app would throw Security Exception and crash.
According to your point :
I saw that in some apps if a Dialog or BottomSheet is open while I
disable the permission, the dialog is no longer displayed when I
return to the app.
There is no lifecycle callback about what you do once permission is denied, but there's method on ActivityCompat which gives you flag if you want to show your own Dialog/BottomSheet
So, you can call shouldShowRequestPermissionRationale() method from ActivityCompat & make your own logic work when it's true.
shouldShowRequestPermissionRationale :
Gets whether you should show UI with rationale for requesting a permission. You should do this only if you do not have the permission and the context in which the permission is requested does not clearly communicate to the user what would be the benefit from granting this permission.
For example,
if you write a camera app, requesting the camera permission would be expected by the user and no rationale for why it is requested is needed.
If however, the app needs location for tagging photos then a non-tech savvy user may wonder how location is related to taking photos. In this case you may choose to show UI with rationale of requesting this permission.
While disabling permission for first time will give you callback in onRequestPermissionResult() method.
I have got this really weird behaviour.
After adding the permissions at runtime for my app, I was checking and testing all cases.
I have the request code in my MainActivity.
So, after I set Never Ask Again and deny the giving permission for ACCESS_FINE_LOCATION, if I press the menu button and then restart the app (the app will call onResume of MainActivity I guess), then the screen is black except a rectangle part in the middle of the screen which varies in size. (Is not the AlertDialog size)
Here some screenshots:
Normal screen
After press menu and then open again can be that it opens with the normal state or with these states:
Or
This is quite weird, anybody had this before?
Thanks for your answers!
Without seeing the code, it's hard to give a very accurate answer.
When requesting permissions, if the user selected 'never ask again', the request permissions response will be denied. I'm GUESSING (due to lack of code) that your app relies on the granted permission to continue loading the UI and executing more code, which it won't do if permission is denied. You need to handle all possible responses when requesting runtime permissions.
if permission is granted: good to go
if permission is denied: check if you should show the permission rationale. This means you display a message to the user explaining why you need the permission.
if shouldShowRationale is true: it means 'never ask again' was NOT checked. Display the message, then ask for permission again.
if should show Rationale is false: it means 'never ask again' was checked and you should probably direct the user to the app settings to turn the permission on if it's required.