日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

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

【關(guān)鍵字】

鴻蒙、彈窗、通知欄、后臺應(yīng)用

【問題描述】

近期華為手機(jī)更新為HarmonyOS后發(fā)現(xiàn)應(yīng)用在后臺時,通知欄推送消息無法跳轉(zhuǎn)應(yīng)用界面。

參考開發(fā)者聯(lián)盟中的以下文檔【FAQ】【彈窗問題】關(guān)于后臺彈窗問題-華為開發(fā)者論壇 | 華為開發(fā)者聯(lián)盟 (huawei.com)

原因是華為新增了后臺彈窗權(quán)限,根據(jù)提供的Android官網(wǎng)文檔連接需要修改通知為顯示通知,以下把個人的踩坑過程提供給各位參考。

【原因與實現(xiàn)步驟】

參考Android官網(wǎng)文檔連接需要修改通知為顯示通知,并使用了全屏Intent但是發(fā)現(xiàn)并沒有生效,仍然無法跳轉(zhuǎ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權(quán)限,這個權(quán)限是普通權(quán)限并不需要申請使用。

因此具體的修改流程如下:

第一步:

在AndroidManifest.xml中增加USE_FULL_SCREEN_INTENT權(quán)限:

<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>

第二步:

參考官網(wǎng)創(chuàng)建全屏Intent通知,最后使用NotificationManager進(jìn)行通知即可

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);

?欲了解更多更全技術(shù)文章,歡迎訪問https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh?

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。