[英]Android FCM onTokenRefresh() is only called in emulator
I got the problem when I used the Firebase onTokenRefresh() function. 使用Firebase onTokenRefresh()函数时遇到问题。 I saw the below block quotes.
我看到了下面的块引号。
onTokenRefresh in FirebaseInstanceIdService is only called when a new token is generated.
仅当生成新令牌时才调用FirebaseInstanceIdService中的onTokenRefresh。 If your app was previously installed and generated a token then onTokenRefresh would not be called.
如果您的应用先前已安装并生成令牌,则不会调用onTokenRefresh。 Try uninstalling and reinstalling the app to force the generation of a new token, this would cause onTokenRefresh to be called.
尝试卸载并重新安装该应用程序以强制生成新令牌,这将导致调用onTokenRefresh。
But it was only applied to my first emulator not the device. 但这仅适用于我的第一个仿真器而不适用于设备。
When I tried uninstalling and reinstalling the app to force the generation of a new token in the emulator, the token was generated. 当我尝试卸载并重新安装该应用程序以强制在模拟器中生成新令牌时,就生成了令牌。 But in the device, the token wasn't generated.
但是在设备中,没有生成令牌。 And I also tried to install the app by creating another emulator to see if a token was generated.
我还尝试通过创建另一个模拟器来查看是否生成了令牌来安装该应用程序。 But, it also didn't.
但是,它也没有。
What is the problem?.. Here is my code. 这是什么问题?..这是我的代码。
@Override
public void onTokenRefresh() {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
sendRegistrationToServer(refreshedToken);
}
and Manifest.xml 和Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".FireBaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".FirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
</application>
Please someone helps me.. 请有人帮我..
Please make sure that your device is connected to the internet. 请确保您的设备已连接到互联网。 It may take a few seconds to generate the token so check the token not directly after the start of the application.
生成令牌可能需要几秒钟,因此在应用程序启动后不要立即检查令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.