Ich verwende die Evernote Android-Job, um Aufgaben zu planen.Evernote Android-Job setExact
Jetzt bin ich mit der setExact
Methode, eine Aufgabe zu einem bestimmten Zeitpunkt
jedoch auslösen, es zu der bestimmten Zeit nicht ausgelöst.
Das ist meine Klasse, die die Jobklasse
public class JobController extends Job {
public static final String TAG = "job_tag";
@Override
protected Result onRunJob(Params params) {
PendingIntent pi = PendingIntent.getActivity(getContext(), 0,
new Intent(getContext(), MainActivity.class), 0);
Notification notification = new NotificationCompat.Builder(getContext())
.setContentTitle("Android Job Demo")
.setContentText("Notification from Android Job Demo App.")
.setAutoCancel(true)
.setContentIntent(pi)
.setSmallIcon(R.mipmap.ic_launcher)
.setShowWhen(true)
.setColor(Color.RED)
.setLocalOnly(true)
.build();
NotificationManagerCompat.from(getContext())
.notify(new Random().nextInt(), notification);
return Result.SUCCESS;
}
public static void setAlarm(long alertAt) {
new JobRequest.Builder(JobController.TAG)
.setExact(alertAt)
.setPersisted(true)
.build()
.schedule();
}
}
Das ist mein Job Creator Klasse
public class JobCreator implements com.evernote.android.job.JobCreator {
@Override
public Job create(String tag) {
switch (tag) {
case JobController.TAG:
return new JobController();
default:
return null;
}
}
}
Und schließlich ruft
JobController.setAlarm(1498066440000L);
Dies sind die Protokolle erweitert:
Warning: job with tag job_tag scheduled over a year in the future
Aber 1498066440000
gehört bis 2017
"Die angegebenen Millisekunden werden ab jetzt als Offset behandelt, der Job wird beispielsweise unter' System.currentTimeMillis() + exactInMs' ausgeführt. " https://github.com/evernote/android-job/blob/master/library/src/main/java/com/evernote/android/job/JobRequest.java#L798 –
Oh, das Protokoll macht jetzt Sinn. –