【问题标题】:Unable to get Notifications on Huawei devices with HmsMessageService (HMS push kit)使用 HmsMessageService(HMS 推送工具包)无法在华为设备上获取通知
【发布时间】:2021-12-22 20:14:16
【问题描述】:

我正在使用 HMS 推送工具包来获取通知。通知在大约 1 周前工作正常,但现在当我重新运行该代码时,它无法正常工作。 我交叉检查了所有东西,但找不到任何东西。 我使用的依赖是:

implementation 'com.huawei.hms:push:5.1.1.301'

我也在我的项目中添加了 agconnect-services.json。 还在清单中添加了应用程序 ID。 SHA-256 密钥也可以。

接收通知的代码是:

public class HMSMessageService extends HmsMessageService {

@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
    
    }
}

我还在清单文件中添加了此服务的标签。

我也尝试使用 HMS 工具包(android studio 中的编码助手),从那里发送通知是成功的,但我没有在应用程序上收到它。

要查看Logcat 日志,请点击here

【问题讨论】:

    标签: android notifications huawei-mobile-services huawei-developers huawei-push-notification


    【解决方案1】:

    根据您提供的内容,使用以下方法接收数据消息,而不是通知消息。并且通知消息会显示在设备上。

    public class HMSMessageService extends HmsMessageService {
    
    @Override
    public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
        
        }
    }
    

    如果还是无法收到通知,可以提供logcat日志和token数据存储位置等信息,我们可以据此分析这个问题并尝试提供帮助。

    【讨论】:

    • 是的,我知道,我无法同时获得数据和通知消息。屏幕上不显示任何内容(未收到任何通知)
    • hi@FaizanAhmad,感谢您的反馈。能否留下您的 appId、logcat 日志和令牌数据存储位置?让我查资料看看问题。
    • AppID: 104661163 我添加了有问题的logcat日志链接,请看一下。能否请您解释一下令牌数据存储位置,我无法理解您在问什么。
    • hi@FaizanAhmad,抱歉,根据您提供的日志,我们无法捕获关键信息。您可以运行以下命令来捕获系统日志的新副本吗? 1. 运行以下命令连接设备:adb logcat -v time 2. 重现问题。 3、按Ctrl+C完成日志采集。
    • 对不起,这是后端问题。由于一些安全问题,有一个检查导致我们无法获得 HMS 通知。顺便说一句,非常感谢。
    【解决方案2】:

    可能您的设备在内部网络中并且有一些安全控制,请在您的防火墙中配置推送服务器的IP地址和端口: https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/restrictions-0000001050040064#section10881161131412

    If a firewall is configured on the network of your app users, ensure that the following port numbers and IP addresses are enabled to allow traffic, so that your message delivery rate will not be affected:
    
    Port numbers:
    
    443
    5223
    IP addresses:
    
    49.4.0.0/20
    80.158.0.0/16
    114.119.0.0/20
    121.36.0.0/20
    159.138.0.0/20
    160.44.0.0/16
    

    【讨论】:

      【解决方案3】:

      这是由于一些后端问题。 由于安全原因,有一些检查(IP 被阻止),因此我无法收到通知。 (但奇怪的是,由于后端检查,只有 HMS 通知被阻止,而不是 Firebase 通知)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-05-08
        • 1970-01-01
        • 1970-01-01
        • 2022-11-28
        • 2015-07-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多