![](/img/trans.png)
[英]How do I get push notifications to show when foreground_show is set to false and my app is in the background?
[英]Xamarin HMS Push Kit, notification message, parameter "foreground_show" is ignored?
根據華為官方文檔,“您可以設置 message.android.notification.foreground_show 字段,使通知消息不被 NC 顯示。在這種情況下,當您的應用程序在前台運行時,通知消息將透明傳輸到您的應用程序,並由您的應用程序處理和顯示。”
示例代碼:
{
"message": {
"notification": {
"title": "message title",
"body": "message body"
},
"android": {
"notification": {
"foreground_show": false,
"click_action": {
"type": 1,
"action": "com.huawei.codelabpush.intent.action.test"
}
}
},
"token": [
"pushtoken1"
]
}
}
我對這個參數有問題,它似乎只是被忽略了。 我創建了一個實現 HmsMessageService 類的消息服務,然后覆蓋了它的 OnMessageReceived(RemoteMessage message) 方法。
我的應用程序成功從服務器獲取訪問令牌,在前台接收數據消息,我的設備在應用程序終止或在后台接收通知消息,然后在用戶點擊時啟動應用程序,但當應用程序在前台時我仍然無法攔截通知消息.
有沒有其他人有這個問題?
您必須為您的 Activity 實現IHmsPushEvent接口,否則您將無法監聽事件。 該接口的函數提供監聽 HmsPush 事件。
解決方案:
示例代碼:
public void OnMessageReceived(RemoteMessage message)
{
string MethodName = MethodBase.GetCurrentMethod().Name;
RemoteMessage.Notification notification = message.GetNotification();
Log.Info(MethodName,$"Title: {notification.Title}\nBody:{notification.Body}");
}
有關更多詳細信息,請參閱文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.