【问题标题】:Android Tablet - Get Unique Device IDAndroid 平板电脑 - 获取唯一设备 ID
【发布时间】:2011-04-06 06:56:02
【问题描述】:

我们如何从 Android 平板电脑(Android 3.0 SDK HoneyComb)中获取唯一设备 ID?

我还发现我们可以使用以下方法获取唯一的 Android 设备 ID: 字符串 deviceId = Settings.System.getString(getContentResolver(), Settings.System.ANDROID_ID);

但是Here 写的是Although, it is not guaranteed that the Android ID will be an unique identifier.

我也经历了一些 SO Questions:

  1. Is there a unique Android device ID?
  2. How to find serial number of Android device?

也参考了这篇文章:http://android-developers.blogspot.com/2011/03/identifying-app-installations.html

但我很困惑how do we get/have Unique Device ID from the Android Tablet type of Device?

【问题讨论】:

    标签: android


    【解决方案1】:

    我知道这个问题很老,但它可能会被找到它的人发现,因为 android ID 不能保证工作,在某些情况下它甚至可能是空的,或者在有根手机上很容易改变。

    我所做的是在生成 UUID 的方法中将 Android ID 与 WiFi MAC 地址结合起来:

    private void generateDeviceId() {
        final String macAddr, androidId;
    
        WifiManager wifiMan = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInf = wifiMan.getConnectionInfo();
    
        macAddr = wifiInf.getMacAddress();
        androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
    
        UUID deviceUuid = new UUID(androidId.hashCode(), macAddr.hashCode());
    
        // Maybe save this: deviceUuid.toString()); to the preferences.
    }
    

    不要忘记将权限添加到 AndroidManifest。

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
    

    祝你好运!

    【讨论】:

      【解决方案2】:

      从 Android 2.2 开始,ANDROID_ID 几乎可以保证是唯一的。

      最近在 Android 开发者博客上有 an article 讨论这个问题。

      【讨论】:

      • 感谢支持,在我使用 3.0 开发应用程序时,将 ANDROID_ID 用于 Android 3.0 Honeycomb 是否可行?
      • 是的。从那个博客来看,Honeycomb 有一个唯一的 ANDROID_ID。
      • 嘿,亲爱的,我之前也列出了相同的链接:android-developers.blogspot.com/2011/03/…。我经历过,但我很困惑。所以在这里问了一个问题。
      • @PM:博客条目的关键是 ANDROID_ID 从 Android 2.2 开始生成一个可靠的唯一编号。我想你的目标是蜂窝?那你就很好了,Honeycomb 包含了 2.2 的所有功能。
      • 实际上,在 Android 2.2 中,有一个 bug,它可以让不同的设备拥有相同的 Android ID(更多信息请参见 here)。此错误已在 Android 2.3 中修复。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-06
      • 2011-08-16
      • 2012-12-28
      • 1970-01-01
      相关资源
      最近更新 更多