Search code examples
androidandroid-permissions

Detect location for Android AppWidget without background location permission


I have an app for providing a weather forecast for a chosen location, which includes a widget. As an option, the user can choose for the app and widget to show weather for the device's location, which is clearly a useful feature for the user.

For this, location permission is required (at least ACCESS_COARSE_LOCATION). And for the widget, because it (optionally) updates every e.g. hour in the background, without an app open in the foreground, this requires background location permission to be granted (ACCESS_BACKGROUND_LOCATION) in order to get the latest device location at the time the widget updates.

But because of a tightening of policy taking effect, updates to my app are now being rejected by Google. Apparently I have to remove the background location permission. Which is a shame because it is (a) clearly a useful feature from a user perspective; (b) entirely optional... the user does not have to grant it if they do not want to... the user is not forced into it and there is an explanation given as to why background location permission is required for a widget... the app itself is still usable (with detected location) without granting background location permission.

Is there any way to get the device's location for use in a widget, without the ACCESS_BACKGROUND_LOCATION permission? Currently I am using the following to get the location with the FusedLocationProviderClient :

FusedLocationProviderClient mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
mFusedLocationClient.getLastLocation().addOnCompleteListener(new LocationOnCompleteListener(context, listener, appWidgetId));

Solution

  • Here is my answer: (a) it isn't possible to get the device's location for use in a widget without background permission; and (b) Google is losing the plot with its raft of new policies.

    From what I have gleaned from a frustrating email exchange with Google, the upshot is that any app that has a widget that provides a "use device location" feature as an option (i.e. entirely optional... user choice and all that), and otherwise uses a fixed location of the user's choosing, must now make "use device location" as the default, so that app reviewers can see the "prominent disclosure" pop up without having to go into a menu (to enable the option)... so that they can tick this particular checkbox in their review checklist.

    Apparently the use of background location must also be "critical to the primary purpose of the app". As it's an option (it can be turned on or off), I guess this means that it is not "critical to the primary purpose of the app". So maybe the upshot is that this useful option needs to be dropped completely. Or maybe I need to make it a requirement that the user enables background location, even if they don't want or need it?

    What happened to user choice? Trust in the user to use their intelligence to make an informed choice? Gone.