Android 点击通知进入正在运行的程序
来源:互联网 发布:手机cad软件中文版 编辑:程序博客网 时间:2024/06/05 18:51
好久没写文章,今天遇到一个新需求,app正在通话过程切换到后台,点击通知栏的时候 回到通话界面。
直接上代码吧
首先是实现通知的代码
NotificationCompat.Builder notificationBuild =null; int NOTIFY_ID = 100; NotificationManager mNotificationManager; boolean isHasNotification = false; android.app.Notification notification; /** * 显示通知栏 */ public void showNotification(String title,String content){ if (mNotificationManager == null&&!isHasNotification){ Intent deleteIntent = new Intent(this, NotificationTipsReceiver.class); notificationBuild = new NotificationCompat.Builder(this); notificationBuild.setAutoCancel(false);//设置能手动取消 notificationBuild.setOngoing(true);//设置不能取消 notificationBuild.setContentTitle(title); notificationBuild.setSmallIcon(R.mipmap.icon);//设置图标 notificationBuild.setTicker("小尾巴 正在接单中"); notificationBuild.setDefaults(android.app.Notification.DEFAULT_ALL); notificationBuild.setPriority(android.app.Notification.PRIORITY_MAX); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, deleteIntent, 0); notificationBuild.setContentIntent(pendingIntent); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); } notification = notificationBuild.build(); mNotificationManager.notify(NOTIFY_ID, notification); isHasNotification = true; }
下面是通知点击处理类
public class NotificationTipsReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //判断app进程是否存活 boolean isApplive = SystemUtil.isAppAlive(context, "com.iol8.te.tr"); Intent dialogIntent = new Intent(context, DialogueActivity.class);dialogIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED|Intent.FLAG_ACTIVITY_NEW_TASK);//注意这里是关键 经过测试Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED也可以用Intent.FLAG_ACTIVITY_SINGLE_TOP 也可以做到 具体区别没有去深入测试 if (isApplive) { if (WYIMManager.isDialogue) { if (!SystemUtil.isAppRunningForeground(context)){//app在后台运行 context.startActivity(dialogIntent); } return; } } }}
另外附上一个Intent的flag 启动介绍(感谢这位大神的分享)
Android Intent flag 介绍
0 0
- Android 点击通知进入正在运行的程序
- android开发之让Android点击通知栏信息后返回正在运行的程序
- android开发之让Android点击通知栏信息后返回正在运行的程序
- Android通知之通知栏点击通知后返回正在运行的程序,而不是一个新Activity
- Android通知之通知栏点击通知后返回正在运行的程序,而不是一个新Activity
- Android点击通知栏信息后返回正在运行的程序,而不是一个新Activity
- android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序
- android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序
- 点击通知跳转到正在运行程序的栈顶activity
- 正在运行的android程序,再次点击程序图标避免再次重新启动程序解决办法
- Android单击通知栏后返回正在运行的程序并跳转到指定fragment页面
- 进入正在运行的docker
- android点击系统通知Notification,进入指定的activity
- Android 消息通知栏返回正在运行的Activity
- android监听正在运行的程序
- android 正在运行的程序与界面
- Android 无法获取正在运行的程序
- iOS 运行程序和进入后台通知
- Dynamics CRM2016 Web API获取实体元数据Picklist属性的Text&Value
- /dev/zero和/dev/null
- 模板方法模式详解(包含与类加载器不得不说的故事)
- HashMap的实现原理
- js获取滚动条距离浏览器顶部,底部的高度
- Android 点击通知进入正在运行的程序
- 涉及公共健康问题的实施强制许可办法出台
- 11种将InputStream转换成String的方法以及性能分析
- POJ 2167 Irrelevant Elements
- Material Design系列之配色设置
- NVIDIA Jetson TX1(2)
- 大白话解析模拟退火算法、遗传算法
- C#实现邮件发送的功能
- 软件项目将死的27个征兆