我有一個應用程序,並希望每天在特定時間發送通知。 這是我的代碼:在android中發送通知
AlarmManager am = (AlarmManager)getBaseContext().getSystemService(alarm);
Intent intent = new Intent("WAKE_UP");
PendingIntent sender = PendingIntent.getBroadcast(getBaseContext(), 0, intent, 0);
time use AlarmManager.set().
am.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis() , AlarmManager.INTERVAL_DAY, sender);
// Prepare intent which is triggered if the
// notification is selected
Intent intent2 = new Intent(this, NotificationReceiverActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent2, 0);
// Build notification
// Actions are just fake
Notification noti = new Builder(this)
.setContentTitle(" boghche " + "shake")
.setContentText("Shake kon :/").setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
但我不能在特定的時間發送。
http://stackoverflow.com/questions/23440251/how-to-repeat-notification-daily-on-specific-time-in-android通過背景/ 23440985#23440985 – 2014-09-10 10:02:22
什麼是API級別? – Skynet 2014-09-10 10:04:20