Jump to content
Sign in to follow this  
Dave Nottage

A user friendly way of showing location permissions settings on Android

Recommended Posts

Posted (edited)

I have code that requests location permissions at runtime, however of course the user might deny that permission. In case they made a mistake, or change their mind, I want to be able to give the user the opportunity to grant the permission because attempting to request the permission in code will result in the user not being prompted, and the permission being denied.

 

Unfortunately, there does not seem to be an easy way (at least on Android 11) of providing this. The following code will show the Location Permissions settings for the device:

var
  LIntent: JIntent;
begin
  LIntent := TJIntent.JavaClass.init(TJSettings.JavaClass.ACTION_LOCATION_SOURCE_SETTINGS);
  TAndroidHelper.Activity.startActivityForResult(LIntent, 0);
end;

However the user then has to - Tap the "App access to location" item:
image.png

 

Scroll down to the "Denied" section and tap the app in question:

 

image.thumb.png.877bbaf1b7a80979e2811eb8dc47d525.png

 

Then select whichever option is appropriate (for this particular app it's "Allow all the time")

image.thumb.png.110d49b5f1df86b1e0f6c262302d61c4.png

 

Then the user needs to either tap the back arrow until the settings screens disappear (Cannot use the app switcher to switch back to the app)

 

This is obviously a horrible user experience. Does anyone know of a better way?

 

Edited by Dave Nottage
Remove superfluous image

Share this post


Link to post

I've improved the experience somewhat, by opening the App Info screen instead using this code:

var
  LIntent: JIntent;
  LUri: Jnet_Uri;
begin
  LUri := TJnet_Uri.JavaClass.fromParts(StringToJString('package'), TAndroidHelper.Context.getPackageName, nil);
  LIntent := TJIntent.JavaClass.init(TJSettings.JavaClass.ACTION_APPLICATION_DETAILS_SETTINGS, LUri);
  LIntent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
  TAndroidHelper.Context.startActivity(LIntent);
end;

Then the user only has to:

  • Tap "Permissions"
  • Tap "Location"
  • Select the appropriate option (e.g. "Allow All The Time")
  • Use the app switcher to switch back to the app, or use the back arrow/button 3 times

Still not great, but better 🙂

 

Share this post


Link to post

I have this question 

Is it possible to clear app data and cache to force resetting user permissions setting ?

Not sure if resetting/deleting app data and clearing it would remove permission as i am still Android 4.4.4 user, but i think you can test this, the only thing might be lost is app data (confusedface.png) but these could be stored somewhere on local storage or even sent over wire somewhere.

By searching the internet i found it might be doable.

 

That on one hand, on other if a permission is essential for app functionality then detecting the user choice of permanent denying might be essential to notify the user of this doing, searching the internet i think  this https://github.com/googlesamples/easypermissions might help 

Quote

Required Permissions

In some cases your app will not function properly without certain permissions. If the user denies these permissions with the "Never Ask Again" option, you will be unable to request these permissions from the user and they must be changed in app settings. You can use the method EasyPermissions.somePermissionPermanentlyDenied(...) to display a dialog to the user in this situation and direct them to the system setting screen for your app:

Note: Due to a limitation in the information provided by the Android framework permissions API, the somePermissionPermanentlyDenied method only works after the permission has been denied and your app has received the onPermissionsDenied callback. Otherwise the library cannot distinguish permanent denial from the "not yet denied" case.

So may be combining the above two approaches might enhance the user experience a little.

 

Hope i am not wasting your time, but really love you read your comment on this.

Share this post


Link to post
56 minutes ago, Kas Ob. said:

Is it possible to clear app data and cache to force resetting user permissions setting ?

As far as I can work out, it's not possible to revoke permissions from within an application, however it is possible external to the device, using adb:

 

https://stackoverflow.com/a/32683390/3164070

 

I'm not sure what the use case would be for being able to do it from within the app other than for testing purposes, and that's covered by using adb as per the link above.

Share this post


Link to post
15 minutes ago, Dave Nottage said:

As far as I can work out, it's not possible to revoke permissions from within an application,

Not exactly what i was talking about, i was pointing to force app data delete if that is possible, something like this

https://stackoverflow.com/questions/6134103/clear-applications-data-programmatically

 

I think but not sure because i don't have newer Android, what if you cleared app data and cache, it might clear user permission choices along with it, if a full reset can be performed then the OS might ask again for permission on the next run, that is my point.

Share this post


Link to post

Found this

https://developer.android.com/reference/android/app/ActivityManager#clearApplicationUserData()

Quote

Permits an application to erase its own data from disk. This is equivalent to the user choosing to clear the app's data from within the device settings UI. It erases all dynamic data associated with the app -- its private data and data in its private area on external storage -- but does not remove the installed application itself, nor any OBB files. It also revokes all runtime permissions that the app has acquired, clears all notifications and removes all Uri grants related to this application.

 

  • Like 2

Share this post


Link to post

Dave, on iOS it works the same way, and with the increase in privacy controls year after year, I think there will be no regressions.

 

What many apps do is show a form before the permission request saying that it is necessary to grant X permission and if the user clicks on proceed, then requests the permission. This will avoid almost all permissions being denied. And when that happens, there's nothing to do but ask the user to grant permission on the settings (even Telegram does that).

  • Like 1

Share this post


Link to post
15 hours ago, vfbb said:

This will avoid almost all permissions being denied

Understood, however there will always be someone, and they may still contact support to ask why the app is not working 😉

 

  • Like 1

Share this post


Link to post
Posted (edited)
On 7/23/2021 at 1:57 PM, vfbb said:

What many apps do is show a form before the permission request saying that it is necessary to grant X permission and if the user clicks on proceed, then requests the permission.

Yes, I meanwhile put such "prominent disclosure" dialog in front of all my apps ( even if Windows ) 🙂

No matter if iOS don't require this, I think that is a good policy too.

 

Regarding the permissions I do it similar as in some websites, saying we have "required" permissions, and explaining why they were required.

Also explaining some privacy stuff there.

If the user don't agree's, he should leave the app.

 

But of course the user still can choose other settings in the OS dialog, than he did in the "prominent disclosure".

The whole permission stuff is a permanent pain ....

 

 

Edited by Rollo62
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×