私はすべての回答を試していますが、役に立たないです。私はここで何が欠けていますか?プライベートvoid sendRegistrationToServer(文字列トークン)パラメータトークンは使用されません
コメント欄で述べたようにprivate void sendRegistrationToServer(String token)`{
}
私はすべての回答を試していますが、役に立たないです。私はここで何が欠けていますか?プライベートvoid sendRegistrationToServer(文字列トークン)パラメータトークンは使用されません
コメント欄で述べたように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.
}
}
、あなたはsendRegistrationToServer()
がFCMに使用登録トークンが生成されonTokenRefresh()
、内部で呼ばれていることがわかります。コードのドキュメントは、内部で何が起こるはずかをすでに示しています。sendRegistrationToServer()
:
サードパーティ製のサーバーへのトークンを永続化します。このメソッドを変更して、ユーザーのFCM InstanceIDトークンを、アプリケーションによってメンテナンスされているサーバー側のアカウントに関連付けます。
独自のアプリケーションサーバーへの登録トークンの送信はオプションですが、これを行うことを強くお勧めします(FCM docsを参照)。あなたが将来の使用のためにトークンを持っているかもしれないように。
あなたが求めていることは明確ではありません。 –
利用可能なすべてのメソッドを試しましたが、私のfcmトークンはlogcatに登録されません。パラメータトークンは使用されません。私は、クイックスタートの例のように、メインのアクティビティにボタンを配置しています。 –