Android 实现不同通知栏
来源:互联网 发布:淘宝网二手笔记本 编辑:程序博客网 时间:2024/05/22 05:06
第一步:(不管哪种方式都要先得到通知管理器的实例)
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
一,普通通知栏:
代码如下:
Notification.Builder builder=new Notification.Builder(this); Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.jianshu.com/p/82e249713f1b")); PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,0); builder.setContentIntent(pendingIntent); builder.setSmallIcon(R.mipmap.ic_launcher); builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher)); builder.setAutoCancel(true); builder.setContentTitle("普通通知栏"); mNotificationManager.notify(1, builder.build());
二,自定义布局通知栏:
代码如下:(布局就是一个基本的布局)
notification.bigContentView=remoteViews;notification.contentView=remoteViews;Notification.Builder builder2=new Notification.Builder(this); Intent intent2=new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.jianshu.com/p/82e249713f1b")); PendingIntent pendingIntent2=PendingIntent.getActivity(this,0,intent2,0); builder2.setContentIntent(pendingIntent2); builder2.setSmallIcon(R.mipmap.ic_launcher); builder2.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher)); builder2.setAutoCancel(true); builder2.setContentTitle("折叠通知"); RemoteViews remoteViews=new RemoteViews(getPackageName(),R.layout.layout_view); Notification notification=builder2.build(); notification.bigContentView=remoteViews; mNotificationManager.notify(1,notification);
三,悬挂式的通知:
代码如下:(布局就是一个基本的布局)
Notification.Builder builder3=new Notification.Builder(this); Intent intent3=new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.jianshu.com/p/82e249713f1b")); PendingIntent pendingIntent3=PendingIntent.getActivity(this,0,intent3,0); builder3.setContentIntent(pendingIntent3); builder3.setSmallIcon(R.mipmap.ic_launcher); builder3.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher)); builder3.setAutoCancel(true); builder3.setContentTitle("悬挂通知栏"); Intent XuanIntent=new Intent(); XuanIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); XuanIntent.setClass(this,MainActivity.class); PendingIntent xuanpengdIntent=PendingIntent.getActivity(this,0,XuanIntent,PendingIntent.FLAG_CANCEL_CURRENT); builder3.setFullScreenIntent(xuanpengdIntent,true); mNotificationManager.notify(2,builder3.build());
另外:
VISIBILITY_PUBLIC: 任何情况的显示
VISIBILITY_PRIVATE: 只有在没有锁屏时显示
VISIBILITY_SECRET: 在安全锁下或者没锁屏下显示
Android5.0以后可以通过builder.setVisibility(Notification.VISIBILITY_PUBLIC);设置.
阅读全文
0 0
- Android 实现不同通知栏
- android 通知栏的实现
- android 通知栏的实现
- android 通知栏的实现
- android 通知栏的实现
- android 通知栏的实现
- android 通知栏的实现
- android实现通知栏透明
- android通知栏的实现
- android应用程序,使用不同方法,在activity之中隐藏Title,或者实现FullScreen(隐藏通知栏)显示。
- Android 通知栏(适应不同版本解决方案)
- Android通知栏通知
- Android实现点击通知栏通知恢复前台
- 【Android】使用Notification实现状态通知栏的通知
- Android 实现通知栏通知APP版本更新
- Android类似于滚动的通知栏实现
- android 通知栏的实现(转)
- android 通知栏的实现(转)
- Linux命令版中的yum挂载及配置
- Struts2学习总结(八):拦截器
- Matlab使用串口通讯
- Activity传递对象集合到Fragment
- node-sass问题解决 An error occurred while running npm install
- Android 实现不同通知栏
- 打包python 成exe
- Java 1.8
- jQuery remove()过滤被删除的元素
- ubuntu搭建ss服务器(shadowsocks)
- 浅谈break和continue
- 如何使用github和git进行团队合作开发(队友和owner的仓库连接)
- activiti入门(1)
- 对于守望者逃离的简单思路(贪心)圈一波魔兽粉