android Notification的使用
来源:互联网 发布:软件开发证书含金量 编辑:程序博客网 时间:2024/06/05 16:46
手机的状态栏里出现的消息即是Notification,现在简单介绍下它的使用方法:
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
/**
创建一个PendingIntent,和Intent类似,不同的是由于不是马上调用,需要在下拉状态条出发的activity,所以采用的是PendingIntent,即点击Notification跳转启动到哪个Activity
*/
PendingIntent intent = PendingIntent.getActivity(context, 0, new Intent(context, MyPreferenceActivity.class), 0);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.remoteview);//自定义notification的布局
Notification notification = new Notification.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setTicker("开始下载")
.setContentTitle("title")
.setNumber(1)
.setContent(remoteViews)
.setContentIntent(intent)
.build();
notification.flags = Notification.FLAG_AUTO_CANCEL; // FLAG_AUTO_CANCEL表明当通知被用户点击时,通知将被清除。
manager.notify(NOTIFICATION_FLAG, notification); //为Notification添加flag,
当要手动清除该消息时调用:
manager.cancel(NOTIFICATION_FLAG); // 清除id为NOTIFICATION_FLAG的通知
- Android-Notification的使用
- Android Notification的使用
- android Notification 的使用
- android Notification 的使用
- Android Notification 的使用
- Android-Notification的使用
- android Notification 的使用
- android Notification 的使用
- android Notification 的使用
- android Notification 的使用
- android Notification 的使用
- android Notification的使用
- android Notification 的使用
- android Notification 的使用
- android Notification 的使用
- android Notification 的使用
- android Notification 的使用
- android Notification 的使用
- 大端模式与小端模式
- jQuery.bind()事件
- adb shell screenrecord命令行使用说明
- Masonry介绍与使用实践
- Installing Odoo 9 on Ubuntu 16.04
- android Notification的使用
- Java练习:牛顿迭代法 Vs. 不动点
- Swift与JavaScript交互实战
- leetcode 1.TwoSum--hashmap
- 原生JS查找相邻元素——siblings方法
- 设计模式中的单例模式(线程安全)
- CSS的方框属性(border,padding,margin)
- linux指令--chmod详解
- Android Studio没有自动提示解决方法之一