关闭

获取手机设备id

标签: deviece设备号
56人阅读 评论(0) 收藏 举报
分类:
public class DeviceUtil {
    private static final String LOGTAG = DeviceUtil.class.getSimpleName();
    private static TelephonyManager telMgr;
    private static WifiManager wifiMgr;

    public static String getDeviceId(Context context) {

        initManager(context);
        if (telMgr != null) {
            String str5 = telMgr.getDeviceId();
            LogcatUtils.i("INFO1", "deviceId:" + str5);
            LogcatUtils.i("INFO1", "deviceIdMD5:" + str5);
            if (isInvalid(str5))
                return str5;
        }
        if (wifiMgr != null) {
            WifiInfo localWifiInfo = wifiMgr.getConnectionInfo();

            if (localWifiInfo != null) {
                String str4 = localWifiInfo.getMacAddress();
                LogcatUtils.i("INFO1", "str4:" + str4);
                if (isInvalid(str4))
                    return "MAC:" + str4;
            }
        }
        String str2 = telMgr.getSimSerialNumber();
        if (isInvalid(str2)) {
            String str3 = "SIMSN:" + str2;
            LogcatUtils.i("INFO1", "SIMSN:" + str3);
            return str3;
        }
        return null;
    }

    private static void initManager(Context paramContext) {
        if (wifiMgr == null) {
            Object localObject2 = paramContext.getSystemService(Context.WIFI_SERVICE);
            if (localObject2 != null)
                wifiMgr = (WifiManager) localObject2;
        }
        if (telMgr == null) {
            Object localObject1 = paramContext.getSystemService(Context.TELEPHONY_SERVICE);
            if (localObject1 != null)
                telMgr = (TelephonyManager) localObject1;
        }
    }

    private static boolean isInvalid(String paramString) {
        boolean isInvalid = false;
        if ((paramString != null) && !(paramString.trim().equals(""))) {
            isInvalid = true;
        }
        return isInvalid;
    }
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:15288次
    • 积分:522
    • 等级:
    • 排名:千里之外
    • 原创:39篇
    • 转载:0篇
    • 译文:0篇
    • 评论:1条
    文章分类
    最新评论