Evernote Android-Job setExact



我正在使用Evernote Android-Job来安排任务。

现在我正在使用 setExact 方法在特定时间触发任务

但是,它不会在特定时间触发。

这是我扩展作业类的类

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();
  }
}

这是我的作业创建者类

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;
    }
  }
}

终于打电话

 JobController.setAlarm(1498066440000L);

这些是日志:

Warning: job with tag job_tag scheduled over a year in the future

1498066440000属于2017

是的,就像评论中提到的,它是现在的偏移量,以毫秒为单位。使用 JobController.setAlarm(2_000L); 在 2 秒内启动作业。

最新更新