获取手机设备id
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;
    }
}
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cheng900716lihai/article/details/52368774
文章标签: deviece 设备号
个人分类: Android
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

获取手机设备id

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭