Android UDID 和 iPhone 一样吗?

发布于 2024-09-09 04:57:59 字数 73 浏览 3 评论 0原文

Android 也有像 iPhone 一样的 UDID 吗?如果是,有什么方法可以以编程方式获取它吗?

谢谢 克里斯

Does Android have a UDID like IPhone? If yes, is there a way I can get it programatically?

Thanks
Chris

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

已下线请稍等 2024-09-16 04:57:59

来自 文档

获取设备Id()

返回唯一的设备 ID,用于
例如,GSM 的 IMEI 和 MEID
对于 CDMA 手机。如果设备返回 null
ID 不可用。

From the docs:

getDeviceId()

Returns the unique device ID, for
example, the IMEI for GSM and the MEID
for CDMA phones. Return null if device
ID is not available.

望笑 2024-09-16 04:57:59

获取 Android UDID 非常简单 - 请查看以下代码:

public class DemoActivityActivity extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);

    Log.d(">>>>", "Android ID: " + Secure.getString(getContentResolver(), Secure.ANDROID_ID));
    Log.d(">>>>", "Device ID : " + tm.getDeviceId());

}

要获取设备 ID,您必须在 AndroidManifest.xml 中设置以下权限:

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

要获取 Android ID,您不需要设置任何权限。

It's very easy to get the Android UDID - check out the following code:

public class DemoActivityActivity extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);

    Log.d(">>>>", "Android ID: " + Secure.getString(getContentResolver(), Secure.ANDROID_ID));
    Log.d(">>>>", "Device ID : " + tm.getDeviceId());

}

For getting the Device ID you have to set following permission in AndroidManifest.xml:

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

For getting the Android ID you don't need to set any permission.

人间☆小暴躁 2024-09-16 04:57:59

过去,设备 ID 仅在您启动时将手机与 Google 帐户关联起来注册 Market 后才可用,即在模拟器上不可用。这似乎在 Android 2.2 中发生了变化,其中也为模拟器生成了一个。我不认为它与 IMEI、ICC 或任何其他与手机相关的令牌相关,而是由 Google 网络服务生成的用于识别您的手机的伪唯一令牌。

The Device ID used to only be available if you had signed up for Market by associating your phone with your Google account when you start, i.e. not available on the emulator. This seems to have changed with Android 2.2, where one is generated for the emulator as well. I don't believe it is associated with IMEI, ICC or any other phone-related token, but is rather a pseudo-unique token generated by Google web services to identify your phone.

╭ゆ眷念 2024-09-16 04:57:59

我实现了一个类来获取IMEI / Wifi MAC地址/设备ID,希望它对你有用^^

public class DeviceInfo {

protected static String imeiNumber;
protected static String wifiMacAddress;
protected static String deviceID;

// This method must be called before other method
public static void init(Context context) throws Exception {
    imeiNumber = getImei(context);
    wifiMacAddress = getWifiMacAddress(context);
    deviceID = getDeviceId(context);
}

public static String getDeviceInfo() {
    return deviceID;
}

public static String getImei() {
    return imeiNumber;
}

public static String getWifiMacAddress() {
    return wifiMacAddress;
}

public static String getModel() {
    return Build.MODEL;
}

public static String getOsVersion() {
    return Build.VERSION.RELEASE;
}

protected static String getDeviceId(Context context) throws Exception {
    String imei = getImei(context);
    if (imei != null) return imei;
    String tid = getWifiMacAddress(context);
    return tid;
}

protected static String getWifiMacAddress(Context context) throws Exception {
    WifiManager manager = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = manager.getConnectionInfo();
    if (wifiInfo == null || wifiInfo.getMacAddress() == null)
        return md5(UUID.randomUUID().toString());
    else return wifiInfo.getMacAddress().replace(":", "").replace(".", "");
}

protected static String getImei(Context context) {
    TelephonyManager m = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    String imei = m != null ? m.getDeviceId() : null;
    return imei;
}

protected static String md5(String s) throws Exception {
    MessageDigest md = MessageDigest.getInstance("MD5");

    md.update(s.getBytes());

    byte digest[] = md.digest();
    StringBuffer result = new StringBuffer();

    for (int i = 0; i < digest.length; i++) {
        result.append(Integer.toHexString(0xFF & digest[i]));
    }
    return (result.toString());
}
}

I implemented a class to get IMEI / Wifi MAC address / deviceID, hope it useful for you ^^

public class DeviceInfo {

protected static String imeiNumber;
protected static String wifiMacAddress;
protected static String deviceID;

// This method must be called before other method
public static void init(Context context) throws Exception {
    imeiNumber = getImei(context);
    wifiMacAddress = getWifiMacAddress(context);
    deviceID = getDeviceId(context);
}

public static String getDeviceInfo() {
    return deviceID;
}

public static String getImei() {
    return imeiNumber;
}

public static String getWifiMacAddress() {
    return wifiMacAddress;
}

public static String getModel() {
    return Build.MODEL;
}

public static String getOsVersion() {
    return Build.VERSION.RELEASE;
}

protected static String getDeviceId(Context context) throws Exception {
    String imei = getImei(context);
    if (imei != null) return imei;
    String tid = getWifiMacAddress(context);
    return tid;
}

protected static String getWifiMacAddress(Context context) throws Exception {
    WifiManager manager = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = manager.getConnectionInfo();
    if (wifiInfo == null || wifiInfo.getMacAddress() == null)
        return md5(UUID.randomUUID().toString());
    else return wifiInfo.getMacAddress().replace(":", "").replace(".", "");
}

protected static String getImei(Context context) {
    TelephonyManager m = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    String imei = m != null ? m.getDeviceId() : null;
    return imei;
}

protected static String md5(String s) throws Exception {
    MessageDigest md = MessageDigest.getInstance("MD5");

    md.update(s.getBytes());

    byte digest[] = md.digest();
    StringBuffer result = new StringBuffer();

    for (int i = 0; i < digest.length; i++) {
        result.append(Integer.toHexString(0xFF & digest[i]));
    }
    return (result.toString());
}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文