Notification的原生實現基本能夠包括:java
使用getSystemService(context.Notification_service) 獲取 Notificationmanager 的引用
ui
使用Notification Builder來構建 Notificationcode
使用前面 的 NotificationManager 啓動Notificationget
簡單邏輯代碼以下:
it
獲取NotificationManager的引用:
io
NotificationManager nm = (NotificationManager) mcontext.getSystemService(Context.NOTIFICATION_SERVICE);
2. 構建 Notification
class
Notification.Builder builder = new Notification.Builder(mcontext); builder.setWhen(System.currentTimeMillis()).setContentTitle("contentTitle").setContentText("contentText"); builder.setLargeIcon(bitmap).setSmallIcon(R.drawable.download_icon); builder.setProgress(MaxLength,currentLength,false); // 設定進度條 Notification notification = builder.getNotification();
3.啓動Notificationservice
nm.notify(Notification_id, notification);