Push Notification
Push Notification:推播通知。但是不會顯示在APP的UI上,會顯示在狀態列上提示小訊息。
android 提供NotificationManager 類別,為了
Push Notification。還需要getSystemService() 方法。
例如:
NotificationManager NM;
NM=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
之後還需要 Notification類別創立Notification,並指定屬性。像是圖標、標題、時間.....等等。
例如:
Notification notify = new Notification(android.R.drawable.stat_notify_more,title,System.currentTimeMillis());
接下來的事,建立 PendingIntent 。處理即將發生的事情。比如在通知Notification中用於跳轉頁面,但不是馬上跳轉。
最後一件事,需要呼叫setLatestEventInfo方法,並發出通知的主題和正文詳細信息。
例如:
notify.setLatestEventInfo(getApplicationContext(), subject, body,pending);
NM.notify(0, notify);
之後還需要 Notification類別創立Notification,並指定屬性。像是圖標、標題、時間.....等等。
例如:
Notification notify = new Notification(android.R.drawable.stat_notify_more,title,System.currentTimeMillis());
接下來的事,建立 PendingIntent 。處理即將發生的事情。比如在通知Notification中用於跳轉頁面,但不是馬上跳轉。
例如:
PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(),0);
//當點擊消息時就會向系統發送最後一件事,需要呼叫setLatestEventInfo方法,並發出通知的主題和正文詳細信息。
例如:
notify.setLatestEventInfo(getApplicationContext(), subject, body,pending);
NM.notify(0, notify);
NotificationManager 其他類別
cancel(int id) :取消先前顯示的通知(Notification)的id。
cancel(String tag, int id):取消先前顯示通知(Notification)的tag和id。
cancelAll():取消先前所有顯示的通知(Notification)。
notify(int id, Notification notification):顯示(Notification)物件與識別id。
notify(String tag, int id, Notification notification):
參考文獻
Android - Push Notification
Android推送通知教程
Android - Notification與Notification Manager學習筆記(很詳細)
Android Push Notification推播機制(1)-簡介篇
Android Notification的基本用法,顯示通知列圖片、播放音效、振動(setSmallIcon)
Android中pendingIntent的深入理解
PendingIntent實現原理和代碼
android基礎知識31:PendingIntent
Android - PendingIntent(1) - 基本用法
Android Tutorial 第五堂(1)廣播接收元件 - BroadcastReceiver 與 AlarmManager
[Android] 多個 Pending Intent 注意事項
Android 如何顯示通知訊息(Notifications)?
【Android】PendingIntent 參數說明
Android SDK 超級初學者筆記 (3) - 通知訊息 Notification Bar
Android Notification介紹
Android 狀態列表之訊息通知(Notification)
Java 快速導覽 - String 類別的 trim()
Android Push Notifications using Google Cloud Messaging GCM - Android Example
使用狀態欄傳遞訊息
android判斷程式在後台運行,然後將程式圖示顯示在狀態列
[Android] Notifications 訊息通知/狀態列顯示通知
Android 狀態列表之訊息通知(Notification)(FLAG_AUTO_CANCEL)
Android--通知之Notification
Android Tutorial 第五堂(2)系統通知服務 - Notification(notify、setContentTitle)
沒有留言:
張貼留言