我是靠谱客的博主 坦率小丸子,这篇文章主要介绍Notification通知栏,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//通过获取系统服务得到通知管理者 NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); //自己构建个通知 Notification.Builder notification=new Notification.Builder(MainActivity.this); //设置Title notification.setContentTitle("老师牙疼!!!"); //设置Text notification.setContentText("老师你变胖了"); // 内容下面的一小段文字 notification.setSubText("——记住我叫叶良辰"); // 收上到信息后状态栏显示的文字信息 notification.setTicker("收到叶良辰发送过来的信息~"); // 设置通知时间 notification.setWhen(System.currentTimeMillis()); // 设置小图标 notification.setSmallIcon(R.drawable.ic_launcher); // 设置自定义的提示音(不考) notification.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.niao)); // 设置点击后取消Notification(加了这行代码 点击通知后 通知就会消失) notification.setAutoCancel(true); Intent intent=new Intent(MainActivity.this,TwoActivity.class); // 此处设置点击的activity的跳转 // 第一个参数依旧是Context // 第二个参数一般用不到,所以用0表示取默认值 // 第三个参数就是一个Intent对象 // 第四个参数直接写0 PendingIntent pit = PendingIntent.getActivity( MainActivity.this, 0, intent, 0); // 设置PendingIntent(设置意图) notification.setContentIntent(pit); Notification notify1 = notification.build(); //使用notify将通知显示出来 //第一个参数是id,要为每个通知所指定的id是不同的 (就是判断这是那个一个通知) //第二个参数就是Notification对象 manager.notify(1, notify1);
复制代码
1
2
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.cancel(1);

 

最后

以上就是坦率小丸子最近收集整理的关于Notification通知栏的全部内容,更多相关Notification通知栏内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部