我正在尝试创建在特定日期和时间触发的通知。
public void notify(View v){
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_WEEK, 2);
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.android_logo,"New Alert, Click Me!",calendar);
Context context = getApplicationContext();
CharSequence contentTitle = "Notification Details...";
CharSequence contentText = "Browse Android Official Site by clicking me";
Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com"));
PendingIntent intent = PendingIntent.getActivity(AllClasses.this, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
}
我的代码中的错误是尝试将Calendar实例传递给Notification构造函数。我很高兴使用状态栏通知而不是警报。有没有办法将此日历对象提供给通知?
谢谢!
答案 0 :(得分:0)
变化:
final Notification notifyDetails = new Notification(R.drawable.android_logo,
"New Alert, Click Me!",calendar);
由此;
final Notification notifyDetails = new Notification(R.drawable.android_logo,
"New Alert, Click Me!",calendar.getTimeInMillis());
如果您想定期执行此操作,则应使用向ServiceIntent发送Intent的警报,并在此启动通知。