Skip to content

Instantly share code, notes, and snippets.

@krtek
Last active December 9, 2016 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krtek/b280f7b6a110df8dc8fe17967e9a90c5 to your computer and use it in GitHub Desktop.
Save krtek/b280f7b6a110df8dc8fe17967e9a90c5 to your computer and use it in GitHub Desktop.
Blog Alarmy v Androidu
dispatcher.cancel(JOB_TAG);
compile 'com.firebase:firebase-jobdispatcher:0.5.0'
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
<service
android:exported="false"
android:name=".SmogService">
<intent-filter>
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>"
</intent-filter>
</service>
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