I've implemented GCMNetworkManager PeriodicTask
I've double-checked all steps according to manual, have read all documentation for GCMNetMan
Setting period with one minute - works perfectly. Setting 2 or 5 minutes - nothing works.
Code in Kotlin:
class ScheduleService: GcmTaskService() {
private val TAG = "ScheduleService"
override fun onInitializeTasks() {
Log.wtf(TAG, "onInitializeTasks")
val gcmMan = GcmNetworkManager.getInstance(this)
gcmMan.schedule(PeriodicTask.Builder()
.setPeriod(120000L)
.setFlex(60000L)
.setPersisted(true)
.setService(ScheduleService::class.java)
.setTag(GPSControl.SCHEDULED)
.setUpdateCurrent(true)
.build())
}
override fun onRunTask(taskParams: TaskParams): Int {
Log.wtf(TAG, "onRunTask: ${taskParams.tag}")
GPSControl.trigger(applicationContext, taskParams.tag)
if (taskParams.tag == GPSControl.SCHEDULED)
return GcmNetworkManager.RESULT_RESCHEDULE
else return GcmNetworkManager.RESULT_SUCCESS
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
return super.onStartCommand(intent, flags, startId)
}
}
I'm an idiot. setPeriod()
and setFlex()
accepts argument in SECONDS