android 同时发送几条通知
google API中介绍requestCode中说明是当前未使用,一般都会赋值为0,但是当你发送多个通知,且每个通知都包含Extras时,这个就有用了。这个值可以用来标识不同通知中的Intent,主要是结合后面的flags来使用,比如,发送两个通知,id分别是1和2,当第二次发送1、2的通知时,需要更新前一次通知中的intent内容,如果不用requestCode来标识一下,则默认用最后一次发的通知覆盖前几次的通知intent。
正确是使用方法是:PendingIntent.getActivity(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT); requestCode来标识不同通知,flags中的PendingIntent.FLAG_UPDATE_CURRENT用来使用后面通知更新前面通知,使用这个flag要注意,intent一定不能为null,否则会报空指针错误。
另外,当我们把Activity 启动模式设置为 singleTask 之后 当我们下次 再去 用Intent 启动 这个 Activity 的时候 就不会去调用 onCreate方法 也不能在onRestart()方法中取,而是去调用onNewIntent()方法 然后把Intent中的数据传给它;
activityandroid:name="TestActivity" @Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
int hasMsgNotifyFlag = 0;
if(intent!=null){
Bundle bundle = intent.getExtras();
if(bundle!=null){
hasMsgNotifyFlag = bundle.getInt("id");
}
Log.i( "main tab msg= ", hasMsgNotifyFlag + "");
}
}
/**
* 添加一个notification
*/
public void addNotification(Context context, int id, boolean flag){
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon, "hello,here", System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(context, TestActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("id", id);
intent.putExtras(bundle);
PendingIntent contentIntent = PendingIntent.getActivity(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, "有新消息", id + "", contentIntent);
nm.notify(id, notification);
}
下沉式通知的一种实现 | Android悬浮窗Window应用 当你浏览公众号时来了一条新消息,通知在屏幕顶部会以自顶向下动画的形式入场,而且它是跨界面的全局浮窗(效果如下图)。虽然上一篇中抽象的浮窗工具类已经能实现这个需求。但本文在此基础上再封装一些更加友好的
Android如何给通知channel静音 目前各个市场都要求targetsdkversion要不低于26,也就是android 8.0。 相应的影响很多功能,比如通知。 当targetsdkversion = 26,需要为通知添加channel
奥特曼超人 KARL-Dujinyang-奥特曼超人。作者目前任职于银狐、泡椒游戏公司,曾任职腾为CTO,CSDN技术专家,曾创办过创业go、造梦工厂、米奇云,万能孵化器等,领域涉及逆向安全专家以及全栈工程师,作者目前出书中。
相关文章
- Could not resolve com.android.support:appcompat-v7:28.0.0 错误处理
- Stetho简化Android调试(二)
- Android实现推送方式解决方案 - 长连接+心跳机制(MQTT协议)
- Android耗电分析之Battery Historian工具使用
- Android 短信模块分析(四) MMS之短信的发送与接收
- Android中Service深入学习
- Animation插值器:解决Android Animation 循环执行的停顿问题
- android:四大组件-Activity
- Android 两种注册、发送广播的区别
- Android启动页适配
- Android CoordinatorLayout 的使用
- Android 约束布局对其
- 如何创建高度模块化的 Android 应用
- Android 快速发送邮件
- 【Android 应用开发】Paint 滤镜 颜色矩阵 应用 ( 颜色矩阵使用流程 | 颜色通道值翻倍 | 颜色通道值增加 | 颜色反转 | 底片效果 | 黑白效果 | 复古效果 | 美颜效果 )
- 【Android 事件分发】事件分发源码分析 ( ViewGroup 事件传递机制 七 )
- android ListView/Recyclerview滚动时自动调用onCheckedChanged导致CheckBox状态混乱的解决办法
- android 8.0跨App(进程)发送广播
- android 唤起系统分享文件或发送邮件(附件)
- (原)Android在子线程用handler发送的消息,主线程是怎么loop到的?
- Android如何客制化adb shell进去后显示shell@xxxx的标识
- Android之四大组件、六大布局、五大存储 总结