我想添加到我的应用程序后台服务中,该服务使用给定日期时间和ID指向表格行并附加信息并在给定时间显示状态栏通知。Android,如何将闹钟服务设置为预定义的日期时间并运行通知
有人能给我一个简单的例子我该怎么做?
很多感谢您的任何建议。
我想添加到我的应用程序后台服务中,该服务使用给定日期时间和ID指向表格行并附加信息并在给定时间显示状态栏通知。Android,如何将闹钟服务设置为预定义的日期时间并运行通知
有人能给我一个简单的例子我该怎么做?
很多感谢您的任何建议。
你看过使用AlarmManager来安排你想要做的任何过程吗? (https://developer.android.com/training/scheduling/alarms.html)
UPDATE:传递参数的意图
例如(复制):
// 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");
}
您可以使用挂起的意图触发通知或意向。 例子是here
你好,是的,我看了这篇文章,但我想与警报还存储一些额外的信息,例如ID。 – redrom 2014-09-05 14:38:16
你的意思是把ID传给接收器?您可以在创建意图时设置它(例如ID),然后在接收器启动时检索它。查看更新的代码示例 – alpinescrambler 2014-09-05 14:54:34