我想添加到我的应用程序后台服务中,该服务将给定日期时间和ID指向具有附加信息的表行,并在给定时间内显示状态栏通知。
有人可以给我一个简单的例子我该怎么做?
非常感谢您的任何建议。
答案 0 :(得分:0)
您是否考虑过使用AlarmManager来安排您想要做的任何流程? (https://developer.android.com/training/scheduling/alarms.html)
更新:将参数传递给意图
例如(复制):
// create Intent
PendingIntent alarmIntent;
Intent intent = new Intent(context, AlarmReceiver.class);
intent.putExtra("ID", "ABX1000"); // your ID
alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
// Set the alarm to start at approximately 2:00 p.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 14);
// With setInexactRepeating(), you have to use one of the AlarmManager interval
// constants--in this case, AlarmManager.INTERVAL_DAY.
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, alarmIntent);
在接收器中,获得意图......
@Override
public void onReceive(Context context, Intent intent) {
// Implement code here to be performed when
// broadcast is detected
String myID= intent.getStringExtra("ID");
}
答案 1 :(得分:0)
您可以使用待处理意图触发通知或意图。 示例是here