讓我有一套時間。例如,{"11:40","11:55","16:15","20:05"}
。 首先,我需要在11:40
上顯示一些通知,然後在11:55
等等,直到結束。每個通知都有自己的標題和文本。而且他們不應該更新(我的意思是,如果用戶沒有按下或在狀態欄中刪除11:40顯示的通知,則不應將下一個通知置於前一通知上)。我知道如何使用AlarmManager
和BroadcastReceiver
顯示通知,但我沒有一個正確的想法如何解決這個問題。我想象的解決方案如下:當應用程序第一次打開時,我設置警報顯示通知index = 0
(其中index
是時間陣列的索引)。當顯示第一個通知時,我更新index
併爲下一個通知等設置警報,直到結束。最後,所有操作都會取消,並且不會顯示任何通知。但我無法想象如何構建該想法。如何解決這個問題呢?可能嗎?我需要一個Service
這個嗎?你能給出有用的步驟來解決這個問題嗎?如何輪流顯示通知?
0
A
回答
0
你只需要在給定的時間調用這個方法。
private void notificationManager(Context context, String message,long time) {
try {
long when = //Set your own time here by passing it in the function
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Log.v("message", "," + message);
Intent notificationIntent = new Intent(context, SplashActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setAutoCancel(true);
builder.setContentTitle(context.getString(R.string.app_name));
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
builder.setContentText(message);
builder.setTicker(message);
builder.setLights(Color.GREEN, 500, 500);
builder.setWhen(when);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentIntent(intent);
Notification notification = builder.build();
notification.ledARGB = 0xFFff0000;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
notification.ledOnMS = 100;
notification.ledOffMS = 100;
notificationManager.notify(1, notification);
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire(15000);
} catch (Exception e) {
e.printStackTrace();
}
}
只是打發時間的builder.setWhen以毫秒爲單位,你可以通過創建一個日曆對象,並設置時間在裏面做。它會自動安排這些通知並顯示它們各自的時間。使用for循環來傳遞函數。
希望這hepls
相關問題
- 1. 顯示通知
- 2. 如何通知銀河齒輪
- 3. 安卓:如何顯示通知文本
- 4. 如何顯示本地通知 - Worklight
- 5. 如何在tizen上顯示通知
- 6. 如何關閉突出顯示通知?
- 7. 如何在IntelliJ中顯示通知?
- 8. 如何用按鈕顯示大通知?
- 9. 如何顯示iOS 5通知?
- 10. 如何顯示擡頭通知android
- 11. 如何在IOS中顯示通知
- 12. 如何讓QWebView顯示桌面通知?
- 13. 如何在Android中顯示此通知?
- 14. 如何在iWatch中顯示通知?
- 15. 如何在asp.net中顯示通知
- 16. 如何創建「顯示通知」checkboxpreferene
- 17. 如何顯示通知插件更新
- 18. 如何使用C#顯示通知?
- 19. 如何顯示從推送通知FCM
- 20. 如何顯示多個本地通知
- 21. 如何在android中顯示通知?
- 22. 如何顯示jgrowl通知的數量?
- 23. 如何每週顯示通知?
- 24. 如何顯示任務欄通知?
- 25. 如何在科爾多瓦的通知區域顯示通知?
- 26. 如何在通知顯示在後臺之前處理通知?
- 27. 如何在Windows通知欄中顯示彈出通知
- 28. 顯示通過通知
- 29. 顯示通過jQuery通知
- 30. 如何通過sql顯示輪詢結果
setWhen(長時間)不用於設定日期和時間觸發的通知。請參閱文檔:https://developer.android.com/reference/android/app/Notification.Builder.html#setWhen(long) https://stackoverflow.com/questions/15458705/how-can-i -set時間和日期換通知 – abay