0

I want to track users in specific period and times of days. I start alarm manager in every 2 minutes (i get periodic time from server and this is dynamic in my application) and try to get location about one minute, after that i stopped getting location and i save location taken on DB. anyway, this approach run very well but in api level 23 and above that, my application for doze and standby mode cannot run well and not call alarms in specific time! I used setExactAndAllowWhileIdle method for api level 23 and above that but not worked well.

The documents said, i can't use more alarms in doze and standby mode. My question is, how can track user in android 6 and above?

Fahim
  • 384
  • 5
  • 20

1 Answers1

0

While working with alarm in doze, use setAlarmClock() instead of set() as it is specifically designed for AlarmClocks, so it can run even in doze as well.

Alternatively,

Have you ever heard of Firebase-job-dispatcher ?

Firebase JobDispatcher is an open-source library that provides an API similar to JobScheduler in the Android platform. Firebase JobDispatcher serves as a JobScheduler-compatibility layer for apps targeting versions of Android lower than 5.0 (API level 21).

Firebase JobDispatcher supports the use of Google Play services as an implementation for dispatching (running) jobs, but the library also allows you to define and use other implementations: For example, you might decide to use JobScheduler or write your own, custom code. Because of this versatility, we recommend that you use this Firebase JobDispatcher if your app targets a version of Android lower than 5.0 (API level 21).

You should go for it. They have got pretty good configuration techniques as well.

Paresh P.
  • 6,677
  • 1
  • 14
  • 26
  • Thanks but my program works good in api level 23 and lower. my problem is in api level 23.. and for that i think, i don't need to use this library. – Fahim Oct 15 '17 at 07:33
  • Yeah, in the case of `alarmManager`, check `setAlarmClock()` instead. see my edit. – Paresh P. Oct 15 '17 at 07:40
  • setAlarmClock show an notification to user but i don't want to show any notification and etc to users. – Fahim Oct 15 '17 at 07:42
  • And another question, Can i call setAlarmClock every 2 minutes? or this is wrong? – Fahim Oct 15 '17 at 07:43
  • Of course you can but this is worst case scenario, its like you are waking up device in every 2 minutes and rescheduling some task using `alarmmanager`. Instead use `JobScheduler` to do the same task. – Paresh P. Oct 15 '17 at 07:47
  • Can i use JobScheduler in doze mode in specific time? – Fahim Oct 15 '17 at 07:57
  • Don't know about specific time, JobScheduler usually used to schedule a repetitive task. Just go through the doc, I'm sure you will get the idea. – Paresh P. Oct 15 '17 at 08:04
  • Thanks. but i think JobSchedular again not working well in background in doze mode in api level 23 – Fahim Oct 15 '17 at 08:12