gpt4 book ai didi

android - FirebaseInstanceId.getInstance() 返回 null

转载 作者:太空狗 更新时间:2023-10-29 13:03:09 27 4
gpt4 key购买 nike

我正在将 Firebase 云消息传递集成到 android 中

app build.gradle 看起来像这样

implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-messaging:17.3.3'
implementation 'com.google.android.gms:play-services-auth:16.0.0'


apply plugin: 'com.google.gms.google-services'

应用级别build.gradle中的类路径是

dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.google.gms:google-services:4.0.1'
}

我的 list 就是这样

<service android:name=".firebase.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_artize_a" />

<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />

<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id" />

我的问题是,当我尝试获取 FirebaseInstanceId.getInstance() 时,它返回 null。所以我无法获得 token 。

即使 MyFirebaseMessagingServiceonNewToken 也不会在应用中触发一次。

谁能告诉我为什么我在这里得到 FirebaseInstanceId.getInstance() null 提前谢谢。

我在这里尝试获取 firebase token

private void getFirebaseToken(){
FirebaseInstanceId firebaseInstanceId = FirebaseInstanceId.getInstance();
if(firebaseInstanceId == null){
return;
}


firebaseInstanceId.getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
return;
}

// Get new Instance ID token
String token = task.getResult().getToken();

}
});
}

最佳答案

经过长时间的研究,我发现 list 文件中的 tools:node="replace" 导致 FCM 无法工作。

tools:node="replace" 更改为 tools:node="merge"

通过这个链接

https://github.com/firebase/quickstart-android/issues/477

关于android - FirebaseInstanceId.getInstance() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52627706/

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