【问题标题】:FCM token not generating in Samsung devices in release version of app在应用程序的发布版本中,三星设备中未生成 FCM 令牌
【发布时间】:2020-05-08 03:52:04
【问题描述】:

我正在使用 FCM 在我的应用中发送通知。我的应用程序的第一个版本处于测试阶段,三星设备出现错误,因为这些设备中没有生成 FCM 令牌。这是我生成令牌的代码:

FirebaseInstanceId.getInstance().instanceId.addOnCompleteListener(OnCompleteListener { task ->
                    if (!task.isSuccessful) {
                        return@OnCompleteListener
                    }

                    // Get new Instance ID token
                    val token = task.result?.token

                    val ref = FirebaseDatabase.getInstance().getReference("/users/$uid")
                    ref.child("Message Token").setValue(token)

                })

我还检查了 Google Play 版本的 SplashActivity。代码如下:

private fun checkPlayServices() {
    val apiAvailability = GoogleApiAvailability.getInstance()
    val resultCode = apiAvailability.isGooglePlayServicesAvailable(this)
    if (resultCode != ConnectionResult.SUCCESS)
    {
        if (apiAvailability.isUserResolvableError(resultCode))
        {
            val dialog: Dialog = apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
            dialog.setCancelable(false)
            dialog.setCanceledOnTouchOutside(false)
            dialog.show()
        }
        else
        {
            Log.d("Demo App", "This device is not supported.")
            val dialogApp = AlertDialog.Builder(this@SplashActivity)
            dialogApp.setTitle("Error")
            dialogApp.setMessage("Some features in the app may not work in your device. Download latest version of play services?")
            dialogApp.setCancelable(false)
            dialogApp.setPositiveButton("OK"
            ) { _, _ ->
                GoogleApiAvailability.getInstance().makeGooglePlayServicesAvailable(this).addOnSuccessListener { Toast.makeText(this@SplashActivity,"Google Play Services Updated. Please Logout and Re-Login", Toast.LENGTH_LONG).show() }
                    .addOnFailureListener { Toast.makeText(this@SplashActivity,"Could not update Google Play Services", Toast.LENGTH_LONG).show() }
            }.setNegativeButton("No"){_, _ ->
            }
            dialogApp.show()
        }

    }
}

添加到上面。当我在调试版本的三星真实设备以及模拟器中测试时,令牌已正确生成。事实上,我在一台三星设备上直接从 Android Studio 安装了该应用程序。在这里工作得很好。后来我尝试从 Play Store 在此设备中安装该应用程序。但是在 PlayStore 中出现了一个问题,之后就没有下载了。我不得不将 PlayStore 恢复为出厂设置。发布此消息后,PlayStore 开始正常运行。但是没有生成token。

任何帮助将不胜感激。

【问题讨论】:

  • 你是否在发布模式下启用了proguard?
  • @Mundroid 是的,我启用了 proguard
  • 在调试模式下你有proguard吗?
  • 我在这两种模式下都启用了proguard。那里没有切换任何东西
  • 但我虽然 ProGuard 不会在调试模式下运行

标签: android firebase kotlin firebase-cloud-messaging samsung-mobile


【解决方案1】:

问题出在 Proguard 上。虽然没有直接的方法来处理这个问题,但我可以找到一种解决方法。在 proguard-rules.pro 文件中,我添加了以下行:

-keep class com.google.firebase.** { *; }

这是为了确保 Firebase 不会删除 Firebase 类。到目前为止,即使在三星设备上也能正常工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-29
    • 2015-03-07
    • 1970-01-01
    相关资源
    最近更新 更多