PendingIntent 显示通知

安卓显示通知

PendingIntent pendingIntent=PendingIntent.getActivity(Media.this,0,
                        new Intent(Media.this,Media.class),0);

                NotificationManager manager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

                Notification notification=new Notification.Builder(Media.this)
              .setSmallIcon(R.drawable.icon)  //不设置会不显示通知 .setTicker(
"Ticker Text"+"您有新消息,请注意查收") .setContentTitle("通知标题") .setContentText("通知内容") .setContentIntent(pendingIntent) .setNumber(1)//在TextView的右方显示的数字,可放大图片看,在最右侧。 // 这个number同时也起到一个序列号的左右,如果多个触发多个通知(同一ID),可以指定显示哪一个 .build(); //任然可以使用 不用管 //当用户点击通知时 通知清除 notification.flags=Notification.FLAG_AUTO_CANCEL; //通过通知管理器发起通知 manager.notify(1,notification);

 

posted @ 2017-05-03 21:36  柴米油盐哈哈  阅读(411)  评论(0编辑  收藏  举报