顯示Notification

1.生成NotificationManager 

NotificationManager nm ;

if(nm!=null){

nm = new NotificationManger(context.notification_service);

}


2.生成Notification

Notification notification = new  Notification(R.drawable.logo,"標題",System.currentTimeMillis());

3.設置各種屬性

如:notification.flags = Notification.FLAG_AUTO_CANCEL;

4. 設置打開通知後要跳轉的activity

Intent intent = new Intent(this,mainActivity.class);

PendingIntent pin = PendingIntent.getActivity(context,0,intent,0);

notification.setLatestEventInfo(context,"標題","內容",pin);

5.顯示

nm.notify(id,notification);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章