Android设备是否只有一个静态IP地址,服务器可以识别它们?我想知道simce可以让我的游戏在不需要登录的情况下保存数据.
正如其他人已经回答的那样,不,移动设备通常没有静态IP地址,而是使用DHCP来获取动态IP地址.
但是,要回答基本问题,可以使用java.util.UUID类为用户生成唯一标记.将此生成的令牌保存到您应用的SharedPreferences中,您可以使用它来识别您的用户:
public static String getDeviceUuid(Context context) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
// Attempt to get an existing device uuid
String uuid = preferences.getString("device_uuid_key", "");
if (TextUtils.isEmpty(uuid)) {
// We don't have a device id, generate one!
uuid = UUID.randomUUID().toString();
// Persist the new id to shared preferences
final Editor editor = preferences.edit();
editor.putString("device_uuid_key", uuid);
editor.commit();
}
return uuid;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21315 次 |
| 最近记录: |