【后台弹窗】应用跳转直通车--通知栏通知跳转后台应用
2023-09-11 14:20:22 时间
【关键字】
鸿蒙、弹窗、通知栏、后台应用
【问题描述】
近期华为手机更新为HarmonyOS后发现应用在后台时,通知栏推送消息无法跳转应用界面。
参考开发者联盟中的以下文档【FAQ】【弹窗问题】关于后台弹窗问题-华为开发者论坛 | 华为开发者联盟 (huawei.com)
原因是华为新增了后台弹窗权限,根据提供的Android官网文档连接需要修改通知为显示通知,以下把个人的踩坑过程提供给各位参考。
【原因与实现步骤】
参考Android官网文档连接需要修改通知为显示通知,并使用了全屏Intent但是发现并没有生效,仍然无法跳转到后台Activity中。注意到官网代码中有以下注释:
// Use a full-screen intent only for the highest-priority alerts where you
// have an associated activity that you would like to launch after the user
// interacts with the notification. Also, if your app targets Android 10
// or higher, you need to request the USE_FULL_SCREEN_INTENT permission in
// order for the platform to invoke this notification
不生效的原因是必须要在Manifest中添加USE_FULL_SCREEN_INTENT权限,这个权限是普通权限并不需要申请使用。
因此具体的修改流程如下:
第一步:
在AndroidManifest.xml中增加USE_FULL_SCREEN_INTENT权限:
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
第二步:
参考官网创建全屏Intent通知,最后使用NotificationManager进行通知即可
Intent fullScreenIntent = new Intent(this, CallActivity.class);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Incoming call")
.setContentText("(919) 555-1234")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_CALL)
// Use a full-screen intent only for the highest-priority alerts where you
// have an associated activity that you would like to launch after the user
// interacts with the notification. Also, if your app targets Android 10
// or higher, you need to request the USE_FULL_SCREEN_INTENT permission in
// order for the platform to invoke this notification.
.setFullScreenIntent(fullScreenPendingIntent, true);
Notification incomingCallNotification = notificationBuilder.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(100, incomingCallNotification);
欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh
相关文章
- Tomcat 配置 项目 到tomcat目录外面 和 域名绑定访问(api接口、前端网站、后台管理网站)
- JavaWeb_(MVC)管理员后台商品查询demo
- 新闻发布项目——后台JSP界面adminManage/addNews.jsp
- 【win8技巧】win8快速切换后台应用
- node.js原生后台进阶(二)
- kill killall pkill 杀死php后台进程
- SAP UI5 Fiori 应用在启动时向 ABAP 后台发起的 OData 请求序列的顺序和作用分析
- 在 SAP ABAP Gateway 系统上定义后台系统的 Alias
- 如何找到SAP Fiori 应用里cache-control header是从后台何处设置的
- SAP CRM Fiori 应用 my Opportunities 的后台性能分析
- 在 SAP CRM Fiori 应用上给 Opportunity 订单添加 note 的后台执行明细
- CRM Fiori my note应用的后台ABAP实现
- CRM Fiori my note应用的后台ABAP实现
- SAP UI5 Fiori 应用在启动时向 ABAP 后台发起的 OData 请求序列的顺序和作用分析
- 【华为云技术分享】WeLink服务端API身份验证应用管理后台免登录
- ios9定位服务的app进入后台三分钟收不到经纬度,应用被挂起问题及解决方式
- FastAdmin 后台 UserRule 勾选不完整 Bug 修复
- Servlet程序实战一之前端向后台传值
- WordPress后台地址路径修改方法