How to have two different location update interval in Fused location when app is in foreground (For example: 5 sec) and when app is in background (For example 5 minute)?
Asked
Active
Viewed 192 times
1 Answers
0
You can check to see if the app in in the foreground.
private boolean isAppInForeground()
{
ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> services = activityManager.getRunningTasks(1);
return (services.get(0).topActivity.getPackageName()
.equalsIgnoreCase(getApplicationContext().getPackageName()));
}
Then in the manifest add:
<uses-permission android:name="android.permission.GET_TASKS"/>

mattfred
- 2,689
- 1
- 22
- 38