Handle permissions change while in app - android

I am having a hard time understanding the right way to handle a user changing a permission while my app is still running in the background.
In my app I have a location class that registers for location changes and when the location changes the status is sent to a server. However this runs in the background.
When my app is launched I check with the user if its ok to use location services and if so I proceed with setting up that class. However the user can background my app and go into settings and remove that permission. I can, and will certainly check that the permission is enabled in my location class before asking for a location from the location service to avoid a crash. However I am not in an activity when a location comes in so I am not sure how to prompt them that my app needs location services.
EDIT:
It does seem that android restarts your app if a permission has been revoked in settings. However I have confirmed that as of now android does NOT restart your app if a permission was granted though settings.

I read somewhere that your app gets killed when the user changes the permissions on Android-M so you can be sure that this won't change while your app is running. It will been killed when this changes.
As reference check this video: https://www.youtube.com/watch?v=f17qe9vZ8RM

However I am not in an activity when a location comes in so I am not sure how to prompt them that my app needs location services.
Raise a Notification, alerting the user that your app cannot do its intended work without the permission that they revoked. Have the Notification tie into an Activity via a PendingIntent where the user will be able to grant that permission.

Along with CommonsWare suggestion, you can have the onProviderDisabled() to know which provider (gps, network) has been disabled and accordingly requestLocationUpdate() for the one that is still enabled. If both are disabled, see if at least Cell Location is of useful for your app. If so, you can send Cell Location at least till user see notification and re-enable the permission.Use PhoneStateListener to do that.

I would like to try a more modern 2020+ answer to the core question:
However I am not in an activity when a location comes in so I am not sure how to prompt them that my app needs location services.
However I am not in an activity when a location comes in so I am not sure how to prompt them that my app needs location services.
If you are in a normal end user environment:
Respect the users choice to revoke the permission and only display the missing permissions to the user if she opens your activity.
On modern devices your service needs to display a notification in the bar to even be allowed to continue running - change the notification to show the problem.
You are allowed to just ask for most permissions but the user has the ability to deny on the 2nd attempt. After that you get auto-no without anything displayed.
Some permissions (e.g. write settings and overlay) can be accessed by opening the settingspages for this directly - which can be done from a service but will be seen as harassment.
If you are in a work environment:
Best use an official mdm solution (COPE).There you can totally zombiefy your devices allowing nothing or anything and pretty much anything in between. User cannot even enter settings if you dissallow or not even turn the device off or.. you name it.
And apps can get all permissions they need and be installed automatically from the getgo.
For both (eben in mdm sometimes a more powerful user might be wanted):
Please build an extra Activity or Fragment (if you have one that uses those) dedicated to display why your app needs a permission and a button for the user to initiate the request/opening of settings.
It may be much work but users and google will be happy :)

Related

How do some application by pass the ACCESS_BACKGROUND_LOCATION even when they are using location service even when app killed?

From the android documentation, the ACCESS_BACKGROUND_LOCATION permission should be stated for app that access the background location, user should see the "Allow all the time" option in the permission page of the application.
Yet, there are a lot of sports app, say strava, that track the gps of user continuously, even when app killed or app in background. They didn't even state the permission of ACCESS_BACKGROUND_LOCATION. This can be verify when going to their app permission page, only allow only when using app, ask every time and refuse options are shown. I understand they use foreground service to do such thing, but how come they didn't state for the ACCESS_BACKGROUND_LOCATION permission? Isn't this a must for apps to track user in background as required by Google? Can anyone give me some explaination on this? Thanks

Location Access in Android 11

Google documentation states:
If you request foreground
location and background location
at the same time, the system throws an exception.
Now, suppose I want my app to be able to access location when (i) the device is locked (ii) the device is unlocked and the app is in foreground. Is it possible in this scenario?
According to the documentation page here:
Even if several features in your app require location access, it's
likely that only some of them require background location access.
Therefore, it's recommended that your app performs incremental
requests for location permissions, asking for foreground location
access and then background location access. By performing incremental
requests, you give users more control and transparency because they
can better understand which features in your app need background
location access.
The process for performing incremental requests is as follows:
At first, your app should guide users to the features that require
foreground location access, such as the "share location" feature in
Figure 1 or the "show current location" feature in Figure 2.
It's recommended that you disable user access to features that require
background location access until your app has foreground location
access.
At a later time, when the user explores functionality that requires
background location access, you can request background location
access.
So the short answer is yes. You can use both foreground and background locations in the app, just don't ask for both at the same time.

Do not allow users to deny app permissions

My whole app relies on the fact that location permissions is granted, but when the permissions dialog opens up, there is a button to deny access. Is there a way to remove the deny button, and only allow them to either exit the app or allow the permissions?
I don't think this is allowed as it is overriding an android system feature. Even if you could figure it out it would probably technically violate the Google Play Store terms. (So, you'd have to turn to another market to release to...)
You should just create the UI clear to the user that the location permission is necessary and then display some sort of error message if they deny that, show them a prompt to allow it again before being able to use the app.
You can read more about it here, notice the lines:
Apps that monitor or track a user's behavior on a device must comply with these requirements:
...
Apps must not hide or cloak tracking behavior or attempt to mislead users about such functionality.
This page explains why and how to show your user why your app needs a certain permission.
In short, without resorting to an off brand kernel of android found on the web or something, you probably can't very easily and shouldn't anyway. (For both moral reasons, legal ones, and because like you can just show a dialog box to explain to the user why they should allow the permission... not that hard. If they want to use your app then they will allow it. Simple as that.)
I don't think it is possible. You can't hide the deny option in the app permission option.
the whole point of google giving these option was to try to protect user privacy.
The best option would be to convince the user why they should allow you the location permission.
And now Google has enforced a more strict policy for the app developer. And any unethical way can make your app banned or even worse your dev account ban.
No, I don't think so that you can take control over the allow and deny options in permission because
All the permissions are divided into two categories normal and dangerous permission (also called Runtime permission), the normal permission are automatically granted as you install the app but the dangerous permission needs a runtime permission from API level 23 (Marshmallow) and here's the lame catch for you since the pre Marshmallow devices doesn't had any concept like Runtime permission, so the solution you want will only work in pre Marshmallow devices (and obviously that's not what you want)
The permission dialog isn't handled by the application, the OS takes care of this.
Here's the official link to the Android guide to App Permissions
You can't control the permission request, but.
You could have a view that prompt user to enable location permission which will prompt the location service to be switch on if it is not switched on and allow permission to your app to access location data.
In your application class, you can create a listener that listens for the status of the location service, if its on or off. you can also check if permission is given on by the user to access location in the listener. so at any point, the status change. your listener acts accordingly

How to know if MI phone user has enabled Auto Start for an app

I have an app that I'd like working for a user only if he has enabled push notifications.
On most Android phones this is not a problem since I request for permission to send push notifications and get it through the app code itself, but on MI phones, the user has to proactively open the Security app and give "Auto Start" permission to my app. And that cannot be done programmatically (I've checked).
Now I can inform the user when he downloads my app that he needs to do this, and would like to show the full app to him only after he's done this.
For this, however, I need to know whether (and when) the user has given me that permission.
The question is, how do I find out that the user has done this - gone to the Security app and given my app the Auto Start permission?
I'd greatly appreciate any tips. Thank you.

Is it possible to turn on Location Services forcefully?

I'm creating an app, that heavily relies on LocationServices.
For now I'm asking user to turn them on, and everything works fine.
However, when user clicks "No", the whole point of this app goes to hell.
I can spam user to turn location services on from my Service, however I find this solution extremely non-elegant.
Is there a way to turn this setting on programatically? I don't care for additional permissions or so.
I did my research and I only got what I already did - ask user to turn on location services with a dialog etc.
Is there a way to turn this setting on programatically?
Fortunately, no, for obvious privacy and security reasons, except perhaps on rooted devices.
However, when user clicks "No", the whole point of this app goes to hell.
Then advise the user once (per run of your UI) that your app cannot function, and the user should uninstall your app.
Bear in mind that many more permissions will have this same sort of user-recovable behavior with Android M.
You simply cant , if that was possible then you can easily gather locations which is for some unethical reasons could be sold ... so for security reasons its not possible at all .
you can always force the user to click yes by making a really useful and helpful application that the user simply want to try and cant click no because it wont function at all ...

Categories

Resources