Android手机系统版本号、IMEI、手机厂商、手机型号

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28261207/article/details/82785220

获取手机IMEI号

/**
 * 获取手机IMEI号
 * <p>
 * 需要动态权限: android.permission.READ_PHONE_STATE
 */
public static String GetIMEI(Context context) {

    if (Build.VERSION.SDK_INT >= 23 && ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return "用户未开启获取IMEI的权限";
    }

    TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
    if (tm != null) {
        return tm.getDeviceId();
    } else {
        return "用户未开启获取IMEI的权限";
    }
}

获取当前手机系统版本号

/**
 * 获取当前手机系统版本号
 *
 * @return 系统版本号
 */
public static String GetSystemVersion() {
    return android.os.Build.VERSION.RELEASE;
}

获取手机厂商

/**
 * 获取手机厂商
 *
 * @return 手机厂商
 */
public static String GetDeviceBrand() {
    return android.os.Build.BRAND;
}

获取手机型号

/**
 * 获取手机型号
 *
 * @return 手机型号
 */
public static String GetSystemModel() {
    return android.os.Build.MODEL;
}

猜你喜欢

转载自blog.csdn.net/qq_28261207/article/details/82785220