【发布时间】:2018-01-11 16:37:13
【问题描述】:
我正在尝试启用 Firebase 通知,但似乎无法正常工作。
如果觉得我在这里错过了一步,但我不确定是什么。
我已在同一个应用程序中集成了 firebase auth 和 firebase 数据库,并且两者都按预期工作。
我在我的 android 清单中添加了 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.
}
}
为什么不调用它?我在这里错过了什么?
【问题讨论】:
标签: android firebase firebase-cloud-messaging