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);