日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

【后台弹窗】应用跳转直通车--通知栏通知跳转后台应用

發布時間:2024/1/8 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【后台弹窗】应用跳转直通车--通知栏通知跳转后台应用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

【關鍵字】

鴻蒙、彈窗、通知欄、后臺應用

【問題描述】

近期華為手機更新為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?

總結

以上是生活随笔為你收集整理的【后台弹窗】应用跳转直通车--通知栏通知跳转后台应用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。