0

i am using following code in android to get IMEI number of phone

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(this.TELEPHONY_SERVICE);
        String imei = telephonyManager.getDeviceId().toString();

i have tested it on many phones

1) Samsung Ace (froyo) 2) Galaxy S 3) Galaxy S2 4) Samsung Geo (ginger bread)

works perfect and gives IMEI number

but while running same code on following deivce i get nothing :(

Android Pantech

any one guide me what could be the issue or if i use Device_ID to uniquely identify android device would that work for all devices?

and one more thing i have read in forum it is some times null and few famous devices give same Device_ID

any one put some light on it that what is the best way to uniquely identify device and that piece of code should work on all devices?

any help would be appreciated.

4

3 回答 3

1

任何人都阐明了唯一标识设备的最佳方法是什么,并且该代码应该适用于所有设备?

不幸的是,没有 100% 完美的方式来识别 Android 设备。这是因为谷歌没有为此提供可靠的方法。相反,它建议跟踪应用程序安装(相对于跟踪设备)。这是一个很好的讨论:识别应用程序安装

于 2012-02-03T19:28:33.263 回答
1

没有 SIM 卡的设备没有 IMEI 号码。您可以改为读取 WIFI-MAC 地址(假设每个 android 设备都有 WIFI)

于 2012-02-03T19:20:50.377 回答
0

我创建了一个逻辑来获得我想法中所有设备的独特价值。请看看这个,如果它失败了,请纠正我。我在 10-20 台设备上进行了测试,并尝试安装相同的 rom,我得到了独特的价值,并且在刷新新 rom 后该值也相同。下面是获取唯一值的方法:

public static String getDeviceId(Context context) {

    final TelephonyManager tm = (TelephonyManager)     context.getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, androidId;
    tmDevice = "" + tm.getDeviceId();
    tmSerial = "" + tm.getSimSerialNumber();
    androidId = ""
            + android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    String deviceId = deviceUuid.toString();
    return deviceId;

/*Below line fails on android 4.4 devices sometime so i made the above lines*/
 // return Secure.getString(activity.getContentResolver(), Secure.ANDROID_ID);
}
于 2014-07-04T10:49:57.740 回答