简体   繁体   English

仅在模拟器中调用Android FCM onTokenRefresh()

[英]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.

相关问题 FCM - 永远不会调用onTokenRefresh() - FCM - onTokenRefresh() is never called FCM - onTokenRefresh永远不会在多风味的Android应用程序上调用 - FCM - onTokenRefresh is never called on multi-flavored android app Firebase FCM 强制调用 onTokenRefresh() - Firebase FCM force onTokenRefresh() to be called 从未调用过Android Firebase Cloud Messaging(FCM)onTokenRefresh()并且getToken()返回null - Android Firebase Cloud Messaging (FCM) onTokenRefresh() never called and getToken() returning null OnTokenRefresh从未在Xamarin Android中调用过 - OnTokenRefresh never called in Xamarin Android FirebaseInstanceIdService onTokenRefresh()仅在应用程序运行时调用吗? - Is FirebaseInstanceIdService onTokenRefresh() only called when the app is running? Android Firebase通知“ OnTokenRefresh”未调用 - Android Firebase notification “OnTokenRefresh” not getting called (Android)Firebase云消息传递-从不在特定设备上调用ontokenrefresh - (Android) Firebase cloud messaging - ontokenrefresh never called on specific device 解决Firebase onTokenRefresh不能按时[Android]的解决方案是什么? - What is the solution to Firebase onTokenRefresh not being called on-time [Android]? onTokenRefresh不会在签名的APK中调用,如果安装的先前版本的应用程序没有实现FCM - onTokenRefresh not getting called in signed APK, if previous version of app installed doesn't have FCM implemented
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM