我有一些代码,想要每天早上3点执行一次。我已经阅读了Service类文档,似乎可以使用AlarmManager触发一个意图(Activity或Service),然后在该意图中创建并发布一个消息到Android通知区域。
Calendar threeAM = Calendar.getInstance();
threeAM.set(Calendar.HOUR_OF_DAY,2);
threeAM.set(Calendar.MINUTE,0);
threeAM.set(Calendar.SECOND,0);
threeAM.set(Calendar.MILLISECOND,0);
AlarmManager alarmManager =
(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, myNotifier.class);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, threeAM.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, PendingIntent.getService(context, 1, i , 0));
Log.i("Service TEST", "Alarm set?" );
代码运行没有问题,但没有任何迹象表明警报已设置,并且活动没有启动。我使用的是一个我知道可用的活动。我尝试了try/catch包装,logcat中没有输出信息...
dumpsys
输出中的某个地方。http://developer.android.com/guide/developing/tools/adb.html#shellcommands - CommonsWare