Firebase 通知集成在令牌刷新未被调用



我正在尝试启用火力基地通知,但似乎无法让它工作。

如果感觉我在这里错过了一步,但我不确定是什么。

我在同一应用程序中集成了 firebase auth 和 firebase 数据库,它们都按预期工作。

我在安卓清单中添加了 2 项服务:

<service
android:name="tld.domain.app.lib.firebase.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name="tld.domain.app.lib.firebase.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>

我可以按 Ctrl+单击类,以便将名称指向正确的位置。

我还在类的 onTokenRefresh 方法中添加了一个断点:

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) {
Log.d(TAG, "sendRegistrationToServer: " + token);
// TODO: Implement this method to send token to your app server.
}
}

为什么不叫这个?我在这里错过了什么?

此接收器仅在令牌刷新时触发/调用。对于初始注册,需要显式调用注册方法。

应用需要调用以下方法来获取推送令牌。令牌不会自行生成

FirebaseInstanceId.getInstance().getToken()

有关更多详细信息,请参阅官方示例。确切的代码片段

最新更新