對不起,如果任何這類問題已發佈,我仍然沒有找到我正在尋找的答案。如何創建通知服務?
我的任務很簡單 - 我想創建一個應用程序,在9PM激動地推送通知。
這裏是我發現了什麼我現在有 -
Intent intent = new Intent();
AlarmManager alarm = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 6);
cal.set(Calendar.HOUR, 9);
cal.set(Calendar.AM_PM, Calendar.PM);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 1000*60*60*24 , pIntent);
Notification noti = new Notification.Builder(this)
.setTicker("Ticker Title")
.setContentTitle("Content Title")
.setContentText("Notification content.")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent).getNotification();
noti.flags=Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
我放牧,必須有一種服務的顯示通知。我如何創建它?如果我的代碼不對,請隨時重新制作。
非常感謝!
從API 19開始,所有對setRepeating()的調用都將委託給setInexactRepeating(),因此您無法確定它將在晚上9點完全被觸發。我與我的手機在線,這就是爲什麼我不能幫助你的代碼不幸。 – Endzeit