Reputation: 844
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?
Upvotes: 1
Views: 1112
Reputation: 803
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.
Upvotes: 1