Android RemoteView的应用 二 通知栏
来源:互联网 发布:mac怎么打dota2 编辑:程序博客网 时间:2024/05/17 21:49
这一次我们通过使用RemoteView来制作一个通知栏
这个通知栏由一个ImageView和TextView和Button构成,点击Button会跳转到TwoActivity,点击到其他位置会跳转到MainActivity。
1. 先创建一个Notification
Notification notification = new Notification();
notification.icon =R.drawable.sample;
notification.tickerText = “hello world”;
notification.when = System.currentTimeMillis();
notification.flags = Notification.FLAG_AUTO_CANCEL;
2。 创建RemoteView并引入Notification,这里可以看出这个PendingIntent使id为open_activity2具有点击后能跳转到TwoActivity的能力
RemoteViews remoteViews = new RemoteViews(getPackageName(),
R.layout.widget);
remoteViews.setTextViewText(R.id.msg, “chapter_5”);
remoteViews.setImageViewResource(R.id.icon1, R.drawable.sample2);
PendingIntent openActivity2PendingIntent = PendingIntent.getActivity(this,0,
new Intent(this,TwoActivity.class),PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.open_activity2,openActivity2PendingIntent);
notification.contentView = remoteViews;
3。给Notification本身添加点击回馈,并发送通知
Intent intent = new Intent(this,MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,
intent,PendingIntent.FLAG_UPDATE_CURRENT);
notification.contentIntent = pendingIntent;
NotificationManager manager = (NotificationManager) getSystemService(
Context.NOTIFICATION_SERVICE);
manager.notify(2,notification);
这上面可以看出这个程序并不复杂,主要还是人家给RemoteView集成了
代码下载链接如下:
RemoteView制作自定义Notification - 下载频道 - CSDN.NET
http://download.csdn.net/detail/z979451341/9809506
下期详细讲PendingIntent,这个为何如此厉害
- Android RemoteView的应用 二 通知栏
- Android RemoteView的应用 三 新年倒计时通知栏
- Android RemoteView的应用 一 桌面控件
- android 应用的通知栏
- android -- 通知栏的简单应用
- Android应用消息通知栏的实现
- Android消息通知栏应用
- Android widget 之RemoteView
- Android widget 之RemoteView
- Android widget 之RemoteView
- Android widget 之RemoteView
- Android widget 之RemoteView
- Android widget 之RemoteView
- Android widget 之RemoteView
- android Notification与remoteView
- Android中的remoteView
- Android之RemoteView
- Android widget 之RemoteView
- android 跳转到当前应用的详情页面
- 设计模式 —— 设计模式三大分类与六大原则
- 贪心
- Python 命名空间和内置函数 locals和globals
- bzoj1220: [HNOI2002]跳蚤
- Android RemoteView的应用 二 通知栏
- 用ViewPager制作导航栏
- ES5中新增的Array方法详细说明
- hdu(1709) 母函数
- Java中实现文件的跨服务器上传
- Spring注解中autowired和resource的区别。
- QT中输出中文乱码处理
- 深入ES6(一)历史与简介
- rails 省市区 三级联动