【后台弹窗】应用跳转直通车--通知栏通知跳转后台应用
【關鍵字】
鴻蒙、彈窗、通知欄、后臺應用
【問題描述】
近期華為手機更新為HarmonyOS后發(fā)現(xiàn)應用在后臺時,通知欄推送消息無法跳轉應用界面。
參考開發(fā)者聯(lián)盟中的以下文檔【FAQ】【彈窗問題】關于后臺彈窗問題-華為開發(fā)者論壇 | 華為開發(fā)者聯(lián)盟 (huawei.com)
原因是華為新增了后臺彈窗權限,根據(jù)提供的Android官網(wǎng)文檔連接需要修改通知為顯示通知,以下把個人的踩坑過程提供給各位參考。
【原因與實現(xiàn)步驟】
參考Android官網(wǎng)文檔連接需要修改通知為顯示通知,并使用了全屏Intent但是發(fā)現(xiàn)并沒有生效,仍然無法跳轉到后臺Activity中。注意到官網(wǎng)代碼中有以下注釋:
// 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"/>第二步:
參考官網(wǎng)創(chuàng)建全屏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?
總結
以上是生活随笔為你收集整理的【后台弹窗】应用跳转直通车--通知栏通知跳转后台应用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 零基础学平面设计是自学好还是报班好?
- 下一篇: 中国互联网公司和他们的口号