dax*_*axu 4 java android firebase firebase-authentication firebase-cloud-messaging
我是 FCM 和移动编码的新手。这就是我想要实现的目标:-
我对实施感到困惑。这就是我的想法:
在我网站的代码中,我有一些代码来检测事件是否关闭并根据链接到该事件的设备令牌发送通知。
这是正确的编码方式吗?但是如果用户重启app或者重启手机,不就是我会得到一个新的devicetoken吗?所以我需要存储一些其他标识符来识别用户(例如 google plus 用户名)?
这是正确的编码方式吗?但是如果用户重启app或者重启手机,不就是我会得到一个新的devicetoken吗?所以我需要存储一些其他标识符来识别用户(例如 google plus 用户名)?
是的,这是正确的,并检查以下问题:
您需要使用FirebaseInstanceIdService它来处理注册令牌的创建、轮换和更新。
要检索设备的令牌,请使用以下命令:
FirebaseInstanceId.getInstance().getToken()
Run Code Online (Sandbox Code Playgroud)
在以下情况下,您获得的上述令牌可能会发生变化:
实例 ID 是稳定的,但以下情况除外:
然后在 FirebaseInstanceIdService 中使用此方法,它会在任何一种情况发生时刷新令牌:
@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);
}
Run Code Online (Sandbox Code Playgroud)
获得令牌后,您可以将其发送到您的应用服务器并使用您喜欢的方法进行存储。
更多信息在这里:https : //firebase.google.com/docs/cloud-messaging/android/client
| 归档时间: |
|
| 查看次数: |
6040 次 |
| 最近记录: |