<分区>
我已经尝试了所有可用的答案,但都无济于事。我在这里缺少什么?
private void sendRegistrationToServer(String token)`{
}
<分区>
我已经尝试了所有可用的答案,但都无济于事。我在这里缺少什么?
private void sendRegistrationToServer(String token)`{
}
最佳答案
如评论部分所述,问题含糊不清,但我有点明白你的问题。
sendRegistrationToServer()
是一个可选方法,可以在 Firebase 的大多数示例中看到。来自 GitHub example :
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.
}
}
从这里,您可以看到在 onTokenRefresh()
中调用了 sendRegistrationToServer()
,其中生成了用于 FCM 的注册 token 。代码文档已经说明了 sendRegistrationToServer()
中应该发生的事情:
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.
向您自己的应用服务器发送注册 token 是可选的,但强烈建议这样做(参见 FCM docs )。这样您就可以拥有 token 以备将来使用。
关于android - private void sendRegistrationToServer(String token) 参数 token 从不使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41533795/
相关文章:
Android 自定义 View 应该扩展 AppCompatTextView
java - firebase 访问 token 是否自动刷新?
ios - Firebase 商店 : trying to store to local file gives an error
android - Firebase Cloud Function 向相同的设备发送多个相同的通知
android - 无法解析 : com. google.firebase :firebase-messaging:16. 0.5
java - 安卓 ClassNotFoundException : Didn't find class on path
android - 错误 : Failed to deploy to device, 找不到设备 -cordova 使用 Visual Studio
java - 模拟 firebase android 应用程序
php - Firebase FCM 错误 JSON_PARSING_ERROR : Unexpected token END OF FILE at position