Android Fused Location API - how to use PRIORITY_BALANCED_POWER_ACCURACY
and PRIORITY_HIGH_ACCURACY
in one application?
Hi, I am developing an application that should send periodic location updates. I used the Fuse Location API with the expected intention. (update interval 60 seconds and a minimum size of 100 m). I registered a pending intent locationclient using PRIORITY_BALANCED_POWER_ACCURACY
and the intent service. IntentService was called when the localization changed, and this worked fine for several test drives. But it only works sometimes. When it does not work, I want to use PRIORITY_HIGH_ACCURACY
I noticed that when I use PRIORITY_HIGH_ACCURACY
, it gives good places, but the battery usage is quite large. So I decided to use both PRIORITY_HIGH_ACCURACY
and PRIORITY_BALANCED_POWER_ACCURACY
along with ActivityRecognition.
Initially, the program starts with PRIORITY_BALANCED_POWER_ACCURACY
using LocationPendingIntent, and when there is no update for 2 minutes, I use the LocationListener (and onLocationChanged) method that implements PRIORITY_BALANCED_POWER_ACCURACY
, and if there is still no location, I call PRIORITY_HIGH_ACCURACY
.
The problem I am facing is that after switching to PRIORITY_HIGH_ACCURACY
, the LocationPendingIntent (registered in PRIORITY_BALANCED_POWER_ACCURACY
) always uses PRIORITY_HIGH_ACCURACY
after that. I remove location updates at the end of the onLocationChanged method by calling .removeupdates (locationListener); however, the GPS icon continues to be displayed every minute.
I thought about using static methods for the onLocationChanged method, but I understand that this is not a good practice for an Android application. Also, are there any known issues while using PendingIntent and onLocationChanged? Can you suggest a solution to my problem?
Permissions are set to:
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Any help in this regard would be greatly appreciated.
Thanks.