android中关于notification的最新用法
来源:互联网 发布:淘宝海外旗舰店真假 编辑:程序博客网 时间:2024/06/03 20:43
//通过Button发送一个普通的通知
public void sendNotification1(View v){
//API 11 之前创建通知的方式,已过时
// Notification n = new Notification();
//API 11 之后使用
// Notification.Builder builder = new Notification.Builder(this);
//v4支持包
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
//设置相关的属性
builder.setSmallIcon(R.mipmap.ic_launcher);//设置小图标
builder.setContentTitle(“你有一条短消息”);
builder.setContentText(“有志者事竟成!”);
// builder.setAutoCancel(true);
builder.setDefaults(Notification.DEFAULT_ALL);
builder.setNumber(10);
builder.setTicker(“新消息”);
// builder.setOngoing(true);//设置为常驻通知
//定义一个意图,当点击通知时要打开一个界面(Activity) Intent intent = new Intent(this,MainActivity2.class); intent.putExtra("msg","不断的练习,才会成功"); //参数:上下文,请求编码(没用),意图,创建PendingIntent的方式
// PendingIntent.FLAG_CANCEL_CURRENT: 取消当前的PI,创建新的
// PendingIntent.FLAG_NO_CREATE:如果有就使用,没有不创建
// PendingIntent.FLAG_ONE_SHOT:只使用一次
// PendingIntent.FLAG_UPDATE_CURRENT:如果有,更新Intent,没有就创建
PendingIntent pi = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
//通知的事件
builder.setContentIntent(pi);
//创建一个通知对象 Notification n = builder.build(); //获取系统的通知管理器 NotificationManager nm = (NotificationManager ) getSystemService(Context.NOTIFICATION_SERVICE); //然后发送通知 nm.notify(NID_1,n);}
- android中关于notification的最新用法
- Android中Notification的用法
- android中Notification的用法
- Android中Notification通知的用法
- android notification 的用法
- android notification的用法
- android中notification的用法(简单易懂用法)
- 关于Notification的常见用法
- Android的Notification的用法
- android app notification的用法
- Android Notification的多种用法
- Android Notification的多种用法
- android 中 Notification 关于状态栏的一些操作
- Android中关于setLatestEventInfo()过时以及构建Notification的解决方法
- Android中关于setLatestEventInfo()过时以及构建Notification的解决方法
- Android中关于setLatestEventInfo()过时以及构建Notification的解决方法
- 关于新版本的Notification的用法
- Android中Notification的使用
- HDOJ 1407 测试你是否和LTC水平一样高 就是三个数的平方是否等于一个数
- HDU:1879 继续畅通工程(kruskal)
- p243 第六题 (不完整)
- 简易在线投票系统(php)——发布投票页面
- WIFI 信道
- android中关于notification的最新用法
- 抽象工厂模式
- 【Android】使用SeekBar调整图像的色度、饱和及度亮度
- [LeetCode-119] Pascal's Triangle II(帕斯卡三角形第K行数据)
- 基于连通性状态压缩的动态规划--【插头DP】模板超级详细解释
- linux信息安全_SSL,PKI,CA篇
- POJ Avoid The Lakes
- Openwrt 硬改过程记录
- WebRTC(RTCWeb)学习--------阿冬专栏!!!!