通知:Notification
来源:互联网 发布:阿里云免费ecs 编辑:程序博客网 时间:2024/06/05 16:44
// 创建通知 private void createNotification() { // 创建通知管理者 manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // 创建builder实例 builder = new Notification.Builder(MainActivity.this); // 设置小图标 builder.setSmallIcon(R.mipmap.ic_launcher);// builder.setContentTitle("");// builder.setContentText(""); // 点击后不会自动消失 builder.setAutoCancel(false); // 不会滑动删除通知 builder.setOngoing(false); // 设置优先级 builder.setPriority(Notification.PRIORITY_MAX); // 通知提示语 builder.setTicker("notification is build!"); // 提示音 震动 闪光 都为系统默认 // builder.setDefaults(Notification.DEFAULT_ALL); builder.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.ring)); builder.setDefaults(Notification.DEFAULT_VIBRATE); // pendingIntent跳转 Intent intent = new Intent(MainActivity.this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); notification = builder.build(); // 发起正在运行事件(活动中) // notification.flags = Notification.FLAG_ONGOING_EVENT; // 三色灯提醒 // notification.flags = Notification.FLAG_SHOW_LIGHTS; // 让声音、振动无限循环,直到用户响应 (取消或者打开) notification.flags = Notification.FLAG_INSISTENT; // notification.flags = Notification.FLAG_ONLY_ALERT_ONCE ; // 只有全部清除时,Notification才会清除 // notification.flags = Notification.FLAG_NO_CLEAR; // 自定义通知样式 remoteView = new RemoteViews(getPackageName(), R.layout.layout_guard_notification); remoteView.setTextViewText(R.id.tv_notification_num, sdf.format(System.currentTimeMillis())); notification.contentView = remoteView; manager.notify(1990, notification); }刷新通知:remoteView.setTextViewText(R.id.tv_notification_num, sdf.format(System.currentTimeMillis()));manager.notify(1990, notification);取消通知:二选一manager.cancel(1990);manager.cancelAll();
DEMO链接
阅读全文
0 0
- Notification通知
- Notification通知
- Notification(通知)
- Notification通知
- Notification通知
- notification通知
- Notification 通知
- 通知(Notification)
- Notification通知
- 通知notification
- 通知Notification
- 通知 ------- Notification
- 通知Notification
- Notification--通知
- Notification通知
- 通知 notification
- 通知Notification
- Notification通知
- python爬虫时http协议以及实现代码
- 编码首行缩进使用Tab键好还是空格好?
- Calendar日历类和GregorianCalendar公历类用法的一个小结
- 数据库缓存简单使用
- 博弈论总结
- 通知:Notification
- AngularJS商品订单
- 购物车二级列表MVP封装
- Nmap常用命令
- 【Scikit-Learn 中文文档】随机梯度下降
- hibernate分页
- MVP二级购物车
- SpringMVC--Controller接口控制器详解
- vue使用vuex时展开运算符出错解决方案