【问题标题】:Firebase cloud messaging(FCM) not working on android version below kitkat (4.4)Firebase 云消息传递(FCM)不适用于 kitkat(4.4)以下的 android 版本
【发布时间】:2017-09-09 11:46:45
【问题描述】:

我已经按照文档实现了 FCM,它在 android 版本 4.4(Kitkat) 及更高版本上运行良好,但在 4.3(Jelly Bean) 及更低版本上运行良好。根据 FCM 文档,它说所需的最低版本是 4.0 以及我拥有的播放服务。 FCM 正在生成刷新令牌,当我使用它从我的服务器或 FCM 控制台发送消息时,它不起作用。以下是我的 FCM 清单条目。

Firebase documentation

     <service android:name=".service.RMFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
    <service android:name=".service.RMFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

感谢任何建议。谢谢。

【问题讨论】:

  • 您是否在 4.3 设备中安装了 Google 服务?设备收到令牌?
  • 当您的应用处于后台时,首先尝试从控制台发送消息
  • 我尝试在应用程序处于后台时发送消息,从 FCM 控制台和我的服务器在前台但设备没有收到任何消息。
  • 是的,我有,并且我正在所有设备上获得令牌,包括 android 4.3。
  • 我的问题是上一步。令牌不会在提到的 android 版本的设备上生成!我的意思是 onTokenRefreshed() 在安装应用程序或清除数据后不会被调用。你有解决这个问题的想法吗?

标签: android firebase-cloud-messaging android-4.2-jelly-bean android-4.3-jelly-bean android-4.1-jelly-bean


【解决方案1】:

使用最新的 google-services 插件。

在顶级 build.gradle 中进行更改

buildscript {
// ...
dependencies {
  // ...
  // Add the following line:
  classpath 'com.google.gms:google-services:4.2.0'  // Google Services plugin
}

}

allprojects {
// ...
repositories {
  // Check that you have the following line (if not, add it):
  google()  // Google's Maven repository
  // ...
}

}

在 Modual 级别的 build.gradle 文件中进行更改

 // Add the following line to the bottom of the file:
 apply plugin: 'com.google.gms:google-services'  // Google Play services Gradle plugin

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-09
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-12
    • 1970-01-01
    相关资源
    最近更新 更多