6.4 Notification 通知栏
定义 Notification作为一个时间触发性的交互提示接口,让我们获得消息的时候,在状态栏,锁屏界面显示相应的消息
创建 Notification.Builder builder = new Notification.Builder(this);
属性 builder.setSmallIcon(R.mipmap.ic_launcher); builder.setContentIntent(pendingIntent); builder.setAutoCancel(true); builder.setLargeIcon(BitmapFactory.decodeResource(getResou rces(),R.mipmap.ic_launcher)); builder.setContentText("内容") builder.setSubText("text");
跳转 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.baidu.com")); //构造pendingdintent PendingIntent pendingIntent = PendingIntent.getActivities(this,0,intent,0);
发布 //通过NotificationManager来发出 NotificationManagernotificationManager=(NotificationManag er) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0,builder.build());