手机特定信息获取

获取设备IMEI


/**
     * 获取设备IMEI。
     * @param context 应用程序上下文对象。 
     * @return 设备IMEI。
     */
    public static String getIMEI(Context context) {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String imei = tm.getDeviceId();
        if (!isEmpty(imei)) {
            return imei;
        } else {
            // 获取mac地址。
            WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            if (wifiMan != null) {
                WifiInfo wifiInf = wifiMan.getConnectionInfo();
                if (wifiInf != null && wifiInf.getMacAddress() != null) { // 48位,如FA:34:7C:6D:E4:D7。
                    imei = wifiInf.getMacAddress().replaceAll(":", "");
                    return imei;
                }
            }
        }
        return "";
    }

获取设备UUID,由设备信息产生


/**
     * 获取设备UUID,由设备信息产生。
     * @return 设备UUID。
     */
    public static final String getUUID(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());
        return deviceUuid.toString();
    }

手机机主名称。


/**
     * 手机机主名称。
     * @return 机主名称。
     */
    public static final String getName() {
        String name = android.os.Build.USER;
        if (isEmpty(name)) {
            name = null;
        }
        return name;
    }

基础信息获取


/**
     * 获取手机操作系统版本号。
     * @return 手机操作系统版本号
     */
    public static final String getVersion() {
        return android.os.Build.VERSION.RELEASE;
    }
    /**
     * <p>
     * 当前系统平台。
     * </p>
     * 
     * @return "Android"
     */
    public static final String getPlatform() {
        return "Android";
    }
    /**
     * 获取sdk版本。
     * @return 手机的sdk版本。
     */
    public static final int getSDKVersion() {
        return android.os.Build.VERSION.SDK_INT;
    }
    /**
     * 获取手机型号。
     * @return 手机型号。
     */
    public static final String getModel() {
        return android.os.Build.MODEL;
    }
    /**
     * 获取手机的设备名称。
     * @return 手机设备名称字符串。
     */
    public static final String getPhoneTarget() {
        String temp = android.os.Build.DEVICE;
        temp = temp.replace(" ", "").replace("-", "_").trim();
        return temp;

    }

    /**
     * 获取设备ID。
     * @return 设备名称id。
     */
    public static final String getClientID() {
        String temp = android.os.Build.ID;
        temp = temp.replace(" ", "").replace("-", "_").trim();
        return temp;
    }

/**
     * 查看android手机是否被刷过机.linux系统下root权限可以使用su命令,android本身也是小型的linux系统。
     * @param command "id" 或其他的 su命令。
     */
    public static final boolean runRootCommand(String command) {
        Process process = null;
        DataOutputStream os = null;
        try {
            process = Runtime.getRuntime().exec("su");
            os = new DataOutputStream(process.getOutputStream());
            os.writeBytes(command + "\n");
            os.writeBytes("exit\n");
            os.flush();
            int exitValue = process.waitFor();
            if (exitValue == 0) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            printException(e);
            return false;
        } finally {
            try {
                if (os != null) {
                    os.close();
                }
                process.destroy();
            } catch (Exception e) {
                // nothing
            }
        }
    }
    /**
     * <p>
     * 判断是否root
     * </p>
     * <p>
     * */
public static boolean isJailBroken(){
        boolean result = Utils.runRootCommand("echo test");
        return result;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值