创建Notification
来源:互联网 发布:手机拍照后期制作软件 编辑:程序博客网 时间:2024/04/24 12:12
创建Notification
可以在NotificationCompat.Builder对象中为通知指定UI信息和操作。要创建通知,请调用NotificationCompat.Builder.build(),它将返回包含你的具体规范的Notification对象。要发出通知,可以通过调用NotificationManager.notify()将Notification对象传递给系统。
必要的通知内容
Notification对象必须包含以下内容:
- 小图标,由setSmallIcon()设置
- 标题,由setContentTitle()设置
- 详细文本,由setContentText()设置
简单的Notification,并响应Notification的点击事件到Activity
NotificationCompat.Builder mBuilder = new NotificationCompat .Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("My notification") .setContentText("Hello World!");// 创建跳转的IntentIntent resultIntent = new Intent(this, SettingActivity.class);// 构建人为的Activity任务栈TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);// 在自定义任务栈中为SettingActivity栈底添加底层父Activity,保障SettingActivity被销毁后不会退出应用,而是进入父Activity。stackBuilder.addParentStack(MainActivity.class);//将跳转Intent压入任务栈stackBuilder.addNextIntent(resultIntent);// 通过TaskStackBuilder构建Notification所需要的PendingIntentPendingIntent resultPendingIntent =stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT);//设置Notification.Builder所需要的PendingIntentmBuilder.setContentIntent(resultPendingIntent);NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);// 通过NotificationManager刷新制定ID的NotificationmNotificationManager.notify(mId, mBuilder.build());
代码中的stackBuilder.addParentStack(MainActivity.calss)也可以通过配置文件来设置
<activity name="com.demo.SettingActivit" parent="com.demo.MainActivity"></activity>
0 0
- Notification创建
- 创建Notification
- 创建和触发Notification
- 创建状态栏通知 notification
- android 创建Notification
- 创建notification的方法
- 关于创建notification
- 用NotificationCompat创建Notification
- android wear-创建Notification
- notification | 避免Acitivity重复创建
- android 创建通知栏Notification
- 创建一个Notification (通知)
- Notification (API14) 创建过程
- 笔记9 Notification Notification创建、发送通知及取消通知
- 创建并显示一个 Notification 的步骤
- 【notification】Android 中创建震动通知
- 【notification】Android 中创建状态栏通知
- Notification 安卓 通知的创建
- git学习笔记
- OpenGL 矩阵及变换概念
- (十三)ReactNative--- React.creatClass 和React.component的区别
- Linux基本的架站流程表
- 如何将我的php脚本以守护进程的方式一直运行
- 创建Notification
- 12V85V 降压恒流led驱动方案
- Leetcode 42. Trapping Rain Water
- 解析Rxjava之一---转载自抛物线
- 写入word
- windows上Apache+tomcat实现主备机服务器
- android 尺寸
- IEEE 802.15.4协议完整中文版 - 5.1.2.1 扫描信道
- HIVE 笔记