Last active
December 9, 2016 09:27
-
-
Save krtek/b280f7b6a110df8dc8fe17967e9a90c5 to your computer and use it in GitHub Desktop.
Blog Alarmy v Androidu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dispatcher.cancel(JOB_TAG); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compile 'com.firebase:firebase-jobdispatcher:0.5.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Int periodInSec = 10 * 60 // 10 minut perioda | |
int windowStart =periodInSec - 60; | |
int windowEnd = periodInSec + 60; | |
Job job = dispatcher.newJobBuilder() | |
.setTag(JOB_TAG) // Označení jobu | |
.setService(SmogService.class) // Naše služba | |
.setRecurring(true) // Opakuj | |
.setLifetime(Lifetime.FOREVER) // Donekonečna, dokud není expicitně zastaveno | |
.setReplaceCurrent(true) // Přepiš job pokud již existuje | |
.setConstraints(Constraint.ON_ANY_NETWORK) // Je třeba připoení k internetu, jinak se nespustí | |
.setTrigger(Trigger.executionWindow(windowStart, windowEnd)) //Kdy se má spuštět | |
.build(); | |
dispatcher.mustSchedule(myJob); // Konečně spustit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<service | |
android:exported="false" | |
android:name=".SmogService"> | |
<intent-filter> | |
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>" | |
</intent-filter> | |
</service> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.firebase.jobdispatcher.JobParameters; | |
import com.firebase.jobdispatcher.JobService; | |
public class SmogService extends JobService { | |
@Override | |
public boolean onStartJob(JobParameters job) { | |
// Provést komunikaci se serverem a např. vyhodit notifikaci | |
return false; | |
} | |
@Override | |
public boolean onStopJob(JobParameters job) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment