为什么HMS推动套件onbackgroundRemoteMoteMoteMessageEceived()不在background.js文件中触发

发布于 2025-01-23 18:06:02 字数 3745 浏览 4 评论 0原文

My Ionic capacitor is set as per these

this.hmsPush.setBackgroundFile("public/assets/background.js")

background.js

var data = {
    "key":"value"
};

onGetItemResponse((result)=>{
    console.log(JSON.stringify(result));
});

onBackgroundRemoteMessageReceived((remoteMessage)=>{
    const jsonData = JSON.parse(remoteMessage.data);
    const headlessNotification = {
                "title": "[Headless] " + jsonData.title,
                "message": jsonData.message.replace("{{name}}","YourName")
            };
    const notification = JSON.stringify(headlessNotification);
    HmsLocalNotification.backgroundLocalNotification(notification);
});

HmsPush.setItem("test",JSON.stringify(data));
HmsPush.getItem("test");
HmsPush.removeItem("test");

更新1 这是我尝试发送和数据消息和应用程序已经杀死的日志。

这条线很可疑

04-25 10:20:01.809 W/ActivityManager( 1461): Service starting has been prevented by iaware or trustsbase sInfo ServiceInfo{8882f89 com.huawei.hms.cordova.push.remote.HmsPushMessageService}
04-25 10:20:01.776 I/PushLog110105309( 5138): [SocketRead_09:20:20-233]enter cancelAlarm(Action=com.huawei.android.push.intent.RESPONSE_FAIL
04-25 10:20:01.778 I/PushLog110105309( 5138): [SocketRead_09:20:20-233]process cmdid to receive from pushSrv:44, subCmdId:FF
04-25 10:20:01.783 I/PushLog110105309( 5138): [SocketRead_09:20:20-233]dispatchIntent over
04-25 10:20:01.785 I/PushLog110105309( 5138): [ReceiverDispatcher-209]process push message cmdid from pushSrv:44, subCmdId:FF
04-25 10:20:01.796 I/PushLog110105309( 5138): [ReceiverDispatcher-209]msgType:3 [0:PassBy msg, 1:System notification, 2:normal notification, 3:HCM PassBy msg],userId:0
04-25 10:20:01.799 I/PushLog110105309( 5138): [ReceiverDispatcher-209] closeTokenCheck: false
04-25 10:20:01.802 I/PushLog110105309( 5138): [ReceiverDispatcher-209]app declare HmsMessageService num is: 1
04-25 10:20:01.802 I/PushLog110105309( 5138): [ReceiverDispatcher-209]judge process is running start
04-25 10:20:01.805 I/PushLog110105309( 5138): [ReceiverDispatcher-209]no running process.
04-25 10:20:01.805 W/PushLog110105309( 5138): [ReceiverDispatcher-209]process  com.**** not exist and control 0
04-25 10:20:01.805 I/PushLog110105309( 5138): [ReceiverDispatcher-209]tempDozeWhileListTime = 10000
04-25 10:20:01.805 I/PushLog110105309( 5138): [ReceiverDispatcher-209]add com.**** to doze temp white list
04-25 10:20:01.807 I/PushLog110105309( 5138): [ReceiverDispatcher-209]do not need to apply net.
04-25 10:20:01.809 W/ActivityManager( 1461): Service starting has been prevented by iaware or trustsbase sInfo ServiceInfo{8882f89 com.huawei.hms.cordova.push.remote.HmsPushMessageService}
04-25 10:20:01.809 W/PushLog110105309( 5138): [ReceiverDispatcher-209]start remote message service failed
04-25 10:20:01.813 I/PushLog110105309( 5138): [ReceiverDispatcher-209]message 0A3680A0490F8108 is cached success: true
04-25 10:20:01.814 I/PushLog110105309( 5138): [ReceiverDispatcher-209]send passby message by start service for: com.****,msgID:0A3680A0490F8108
04-25 10:20:01.814 I/PushLog110105309( 5138): [ReceiverDispatcher-209]process cmdid to send to pushSrv:45, subCmdId:FF
04-25 10:20:01.815 I/PushLog110105309( 5138): [ReceiverDispatcher-209]send msg to remote srv success
04-25 10:20:01.815 I/PushLog110105309( 5138): [ReceiverDispatcher-209]handleMessageResponse the response msg is :45,msgId:0A3680A0490F8108,displayPkgName:com.****,flag:1B
04-25 10:20:01.815 I/PushLog110105309( 5138): [ReceiverDispatcher-209]enter AlarmTools:setInexactAlarm(intent:Intent { act=com.huawei.action.push.intent.CHECK_CHANNEL_CYCLE pkg=android } interval:1200000ms

My Ionic capacitor is set as per these instructions. It is able to receive data messages just fine when the app is in the background or foreground. But the background.js script is not being called when the app is killed.

this.hmsPush.setBackgroundFile("public/assets/background.js")

background.js

var data = {
    "key":"value"
};

onGetItemResponse((result)=>{
    console.log(JSON.stringify(result));
});

onBackgroundRemoteMessageReceived((remoteMessage)=>{
    const jsonData = JSON.parse(remoteMessage.data);
    const headlessNotification = {
                "title": "[Headless] " + jsonData.title,
                "message": jsonData.message.replace("{{name}}","YourName")
            };
    const notification = JSON.stringify(headlessNotification);
    HmsLocalNotification.backgroundLocalNotification(notification);
});

HmsPush.setItem("test",JSON.stringify(data));
HmsPush.getItem("test");
HmsPush.removeItem("test");

Update 1
Here is the log when I try to send and data message and the app is already killed.

This line is suspicious

04-25 10:20:01.809 W/ActivityManager( 1461): Service starting has been prevented by iaware or trustsbase sInfo ServiceInfo{8882f89 com.huawei.hms.cordova.push.remote.HmsPushMessageService}
04-25 10:20:01.776 I/PushLog110105309( 5138): [SocketRead_09:20:20-233]enter cancelAlarm(Action=com.huawei.android.push.intent.RESPONSE_FAIL
04-25 10:20:01.778 I/PushLog110105309( 5138): [SocketRead_09:20:20-233]process cmdid to receive from pushSrv:44, subCmdId:FF
04-25 10:20:01.783 I/PushLog110105309( 5138): [SocketRead_09:20:20-233]dispatchIntent over
04-25 10:20:01.785 I/PushLog110105309( 5138): [ReceiverDispatcher-209]process push message cmdid from pushSrv:44, subCmdId:FF
04-25 10:20:01.796 I/PushLog110105309( 5138): [ReceiverDispatcher-209]msgType:3 [0:PassBy msg, 1:System notification, 2:normal notification, 3:HCM PassBy msg],userId:0
04-25 10:20:01.799 I/PushLog110105309( 5138): [ReceiverDispatcher-209] closeTokenCheck: false
04-25 10:20:01.802 I/PushLog110105309( 5138): [ReceiverDispatcher-209]app declare HmsMessageService num is: 1
04-25 10:20:01.802 I/PushLog110105309( 5138): [ReceiverDispatcher-209]judge process is running start
04-25 10:20:01.805 I/PushLog110105309( 5138): [ReceiverDispatcher-209]no running process.
04-25 10:20:01.805 W/PushLog110105309( 5138): [ReceiverDispatcher-209]process  com.**** not exist and control 0
04-25 10:20:01.805 I/PushLog110105309( 5138): [ReceiverDispatcher-209]tempDozeWhileListTime = 10000
04-25 10:20:01.805 I/PushLog110105309( 5138): [ReceiverDispatcher-209]add com.**** to doze temp white list
04-25 10:20:01.807 I/PushLog110105309( 5138): [ReceiverDispatcher-209]do not need to apply net.
04-25 10:20:01.809 W/ActivityManager( 1461): Service starting has been prevented by iaware or trustsbase sInfo ServiceInfo{8882f89 com.huawei.hms.cordova.push.remote.HmsPushMessageService}
04-25 10:20:01.809 W/PushLog110105309( 5138): [ReceiverDispatcher-209]start remote message service failed
04-25 10:20:01.813 I/PushLog110105309( 5138): [ReceiverDispatcher-209]message 0A3680A0490F8108 is cached success: true
04-25 10:20:01.814 I/PushLog110105309( 5138): [ReceiverDispatcher-209]send passby message by start service for: com.****,msgID:0A3680A0490F8108
04-25 10:20:01.814 I/PushLog110105309( 5138): [ReceiverDispatcher-209]process cmdid to send to pushSrv:45, subCmdId:FF
04-25 10:20:01.815 I/PushLog110105309( 5138): [ReceiverDispatcher-209]send msg to remote srv success
04-25 10:20:01.815 I/PushLog110105309( 5138): [ReceiverDispatcher-209]handleMessageResponse the response msg is :45,msgId:0A3680A0490F8108,displayPkgName:com.****,flag:1B
04-25 10:20:01.815 I/PushLog110105309( 5138): [ReceiverDispatcher-209]enter AlarmTools:setInexactAlarm(intent:Intent { act=com.huawei.action.push.intent.CHECK_CHANNEL_CYCLE pkg=android } interval:1200000ms

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烂柯人 2025-01-30 18:06:02

在杀戮状态下,您可以在日志中找到此信息吗? “ ** onMessageReceived **”

您可以使用此命令来捕获日志:
adb logcat -c&& adb logcat -vtime> logcat1.txt

In killing state, can you find this information in log? " ** onMessageReceived ** "

You can use this command to catch log:
adb logcat -c && adb logcat -vtime > logcat1.txt

懒的傷心 2025-01-30 18:06:02

日志告诉根本原因。
04-25 10:20:01.809 W/ActivityManager(1461):IAWare或Trustsbase Sinfo ServiceInfo {8882F89 com.huawei.hms.hms.hms.hms.cordova.push.remote.remote.hmspushmesservice}

解决方案。启动时只需添加一个延迟,

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        Intent intent = new Intent(getContext() ,ServiceName.class);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            startForegroundService(intent);
        } else {
            startService(intent);
        }
    }
},1000);

请参考此URL以获取更多信息: https://blog.katastros.com/a?id=01750-e3e353a0-ceec-4138-b2AA-0C2221BE37C13

the log tells the root cause.
04-25 10:20:01.809 W/ActivityManager( 1461): Service starting has been prevented by iaware or trustsbase sInfo ServiceInfo{8882f89 com.huawei.hms.cordova.push.remote.HmsPushMessageService}

Solution is below. Just add a delay when starting

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        Intent intent = new Intent(getContext() ,ServiceName.class);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            startForegroundService(intent);
        } else {
            startService(intent);
        }
    }
},1000);

please refer to this url for more info: https://blog.katastros.com/a?ID=01750-e3e353a0-ceec-4138-b2aa-0c221be37c13

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文