gpt4 book ai didi

android - 如果用户有多个设备,如何在我的服务器上存储 firebase token

转载 作者:搜寻专家 更新时间:2023-11-01 09:35:57 25 4
gpt4 key购买 nike

我正在使用这个众所周知的代码在我的服务器上保存一个新的 firebase token (来自:Retrieve the current registration 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);
}

问题是,如果用户在其他设备上安装该应用程序,将执行相同的代码,并且之前的 firebase token 将被新 token 覆盖。

所以我必须区分设备,但我该怎么做呢? Device name肯定不够独特。

编辑:不幸的是,Bob Snyder 的建议没有奏效。 FirebaseInstanceId#getId()如果我删除应用程序数据(缓存)或重新安装应用程序,总是不同的。

最佳答案

token 对于每台设备都是唯一的,并且包含应用程序实例 ID。 11 个字符的实例 ID,与 FirebaseInstanceId.getInstance().getId() 返回的相同, 首先出现,然后是冒号,然后是 token 的其余部分。示例:

    eiURDSe_P4q:APA91bFvtCzK...LRpzvQOSdNKioklO

您可以使用实例 ID 作为唯一键来将 token 存储在服务器上。

关于android - 如果用户有多个设备,如何在我的服务器上存储 firebase token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43172532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com