gpt4 book ai didi

android - FirebaseInstanceIdService 不会被调用

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:02:01 24 4
gpt4 key购买 nike

我遵循了互联网上的例子,并在此处和其他网站上复习了许多问题

我构建了我的应用程序,以便它处理 FCM 通知,但我仍然无法找出为什么 FirebaseInstanceIdService 没有被调用。

我在AndroidManifest.xml中声明了它

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

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

我的服务是

public class InstanceService extends FirebaseInstanceIdService {
private static final String REG_Token="REG_Token";

@Override
public void onTokenRefresh() {

String recent_token= FirebaseInstanceId.getInstance().getToken(); // get token from the server

Log.d(REG_Token,recent_token); // show device token in Logcat View

}

我查看了 Logcat,但那里没有 REG_Token。

我尝试调试代码并在 Log.d(REG_Token,recent_token); 处停止,但它并没有就此停止。

我认为该服务根本没有被调用,我找不到原因。

最佳答案

来自 this documentation

The registration token may change when:

  • The app deletes Instance ID
  • The app is restored on a new device
  • The user uninstalls/reinstall the app
  • The user clears app data.

这意味着 onTokenRefresh() 方法不会在每次打开应用程序时调用,而只会在这 4 个事件之一发生时调用。

最简单的方法是卸载该应用程序,然后重新安装该应用程序。安装后,打开应用程序,然后查看 logcat(基于您的代码)。

希望这有帮助:)

关于android - FirebaseInstanceIdService 不会被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41442481/

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