gpt4 book ai didi

android - onTokenRefresh() 永远不会在第一次安装应用程序时被调用

转载 作者:行者123 更新时间:2023-11-29 01:07:29 27 4
gpt4 key购买 nike

我知道还有一些其他帖子与我的帖子类似,但我浏览了解决方案列表但没有结果。我的 Android 应用程序有一个非常简单的 firebase 实现,它应该在启动时检索 token 并通过回调将其传递给主要 Activity 以供以后使用。我听说 token 应该在启动时生成,但在第一次安装应用程序期间,我从未收到它并且我的应用程序崩溃了。如果我再次安装我的应用程序(没有先删除它),一切正常,我得到了我的 token 。

我试过:

  • 将我的 firebase 依赖项更新并整合到应用程序的 build.gradle 文件中
  • 确认我的 list 使用了正确的 firebase 服务/互联网权限
  • 在手动调用 getToken() 之前使用 FirebaseInstanceId.getInstance().deleteInstanceId() 删除我的实例 ID
  • 在多个设备上测试

在第一次安装时查看我的 logcat,我得到了这两个 firebase 错误:

E/FA: Discarding data. Failed to send app launch
E/FA: Failed to get app instance id

我的 InstanceIdService:

public class InstanceIDService extends FirebaseInstanceIdService {

TokenCallback callback;

public void initInstanceIDService(TokenCallback cb) {
this.callback = cb;
}

@Override
public void onTokenRefresh() {
super.onTokenRefresh();

// Get updated token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();

if (refreshedToken != null) {
callback.onTokenReceived(refreshedToken);
}
//pass token to manager for use during authentication
Log.d("Firebase", "Refreshed token: " + refreshedToken);
}

public interface TokenCallback {

void onTokenReceived(String token);
}
}

我的 list :

        <service
android:name="com.projectname.network.MessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="com.projectname.network.InstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>

我的 Gradle 依赖项:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-messaging:11.0.4'
compile 'com.android.support:appcompat-v7:+'
}
apply plugin: 'com.google.gms.google-services'

我在物理设备上进行测试,所有设备都返回相同的行为。

如果有人遇到过这个问题,任何建议或解决方案将不胜感激。

最佳答案

当设备或模拟器运行与所用 Firebase 库版本不兼容的旧版 Google Play 服务时,可能会出现此问题。当这种情况存在时,logcat 将包含此警告消息:

W/GooglePlayServicesUtil: Google Play services out of date.  Requires XXXXXXXX but found XXXXXXXX

解决办法是更新Google Play服务,或者降级Firebase版本。

由于 Firebase API 需要兼容版本的 Google Play 服务,因此最好在应用程序初始化期间使用 GoogleApiAvailability 确认兼容版本的存在。 .

关于android - onTokenRefresh() 永远不会在第一次安装应用程序时被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45845006/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com