【问题标题】:android firebase background notification not working on only vivo deviceandroid firebase后台通知仅在vivo设备上不起作用
【发布时间】:2020-01-09 04:23:22
【问题描述】:

我在后台模式下使用 FCM 推送通知启动服务,但应用程序在终止应用程序后不会收到任何通知。而且我只在vivo设备中遇到了这个问题。在其他设备上,它工作正常。

当我手动启用自动启动时,它会正常工作。但如果没有启用自动启动,它将无法正常工作。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    Intent intent = new Intent(ACTION_MAIN);
    intent.setClass(this, LinphoneService.class);
    intent.putExtra("PushNotification", true);
    startForegroundService(intent);

} else {
    Intent intent = new Intent(ACTION_MAIN);
    intent.setClass(this, LinphoneService.class);
    intent.putExtra("PushNotification", true);
    startService(intent);
}

每当应用在所有设备中收到 Firebase 推送通知时,我都需要启动我的服务,而无需启用自动启动。

【问题讨论】:

    标签: android firebase firebase-cloud-messaging


    【解决方案1】:

    (1) Vivo 和其他中国 OEM(小米、Oppo、Mi)限制后台任务。 - 特别适用于 Android 9 及更高版本。

    到目前为止,启用自动启动是唯一的选择。 您可以提示用户自动启动权限,将他带到设置页面并要求他启用自动启动。 检查此 SO answer

    (2) 忽略battery optimisation的系统对话框

    在此处检查安全问题:默认情况下,所有高于 marshmallow 的应用都启用电池优化。

    https://commonsware.com/blog/2015/11/11/google-anti-trust-issues.html

    您可能希望提示用户禁用电池优化,让应用在后台执行您的任务

    【讨论】:

    • 我已在所有 OEM 的期望 vivo 中管理后台任务,但未启用自动启动。我的后台服务在没有启用自动启动的 oppo、小米设备上运行良好。但只是在vivo设备中出现问题,因为我在仅vivo设备中杀死应用程序后没有收到firebase推送通知。
    猜你喜欢
    • 1970-01-01
    • 2017-05-31
    • 1970-01-01
    • 2017-10-29
    • 2020-04-26
    • 1970-01-01
    • 1970-01-01
    • 2014-04-13
    相关资源
    最近更新 更多