private void sendRegistrationToServer(String token) 参数令牌从不使用

Tam*_*own 4 android firebase firebase-cloud-messaging

我已经尝试了所有可用的答案,但无济于事。我在这里缺少什么?

private void sendRegistrationToServer(String token)`{
}
Run Code Online (Sandbox Code Playgroud)

AL.*_*AL. 5

正如评论部分所提到的,这个问题很模糊,但我有点明白你在问什么。

sendRegistrationToServer()是一个可选方法,可以在 Firebase 的大多数示例中看到。来自GitHub 的示例

package com.google.firebase.quickstart.fcm;

import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;


public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

    private static final String TAG = "MyFirebaseIIDService";

    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. Note that this is called when the InstanceID token
     * is initially generated so this is where you would retrieve the token.
     */
    // [START refresh_token]
    @Override
    public void onTokenRefresh() {
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        // If you want to send messages to this application instance or
        // manage this apps subscriptions on the server side, send the
        // Instance ID token to your app server.
        sendRegistrationToServer(refreshedToken);
    }
    // [END refresh_token]

    /**
     * Persist token to third-party servers.
     *
     * Modify this method to associate the user's FCM InstanceID token with any server-side account
     * maintained by your application.
     *
     * @param token The new token.
     */
    private void sendRegistrationToServer(String token) {
        // TODO: Implement this method to send token to your app server.
    }
}
Run Code Online (Sandbox Code Playgroud)

从这里,您可以看到sendRegistrationToServer()inside 被调用onTokenRefresh(),其中生成了用于 FCM 的注册令牌。代码文档已经告诉了里面应该发生什么sendRegistrationToServer()

将令牌保留到第三方服务器。修改此方法以将用户的 FCM InstanceID 令牌与您的应用程序维护的任何服务器端帐户相关联。

将注册令牌发送到您自己的应用程序服务器是可选的,但强烈建议这样做(请参阅FCM 文档)。这样您就可以拥有令牌以供将来使用。