17

在 Android 应用程序中,如何以编程方式获取主机设备的内部版本号(显示在系统设置 -> 关于平板电脑 -> 内部版本号)以在 Java Android 应用程序中使用?

平板电脑上的系统设置版本号

目前,我正在使用“android.os.Build”。

4

7 回答 7

19

检查此代码..

Build.FINGERPRINT你会得到Build Number设备的。

String mString = "";

    mString.concat("VERSION.RELEASE {" + Build.VERSION.RELEASE + "}");
    mString.concat("\nVERSION.INCREMENTAL {" + Build.VERSION.INCREMENTAL + "}");
    mString.concat("\nVERSION.SDK {" + Build.VERSION.SDK + "}");
    mString.concat("\nBOARD {" + Build.BOARD + "}");
    mString.concat("\nBRAND {" + Build.BRAND + "}");
    mString.concat("\nDEVICE {" + Build.DEVICE + "}");
    mString.concat("\nFINGERPRINT {" + Build.FINGERPRINT + "}");
    mString.concat("\nHOST {" + Build.HOST + "}");
    mString.concat("\nID {" + Build.ID + "}");

    ((TextView) findViewById(R.id.textView1)).setText(mString);

我的设备内部版本号:

我的设备版本号

FINGERPRINT通过上述代码返回

在此处输入图像描述

于 2013-12-20T06:04:56.357 回答
7

我曾经String Build_Number = Build.DISPLAY;获得电话设置中显示的内部版本号

于 2017-08-14T02:16:48.483 回答
6

要仅获取设置中“关于设备”中显示的 Build Number 值,我们可以使用以下静态方法:

/**
 * This method returns Build Number of the device from the OS Build fingerprint
 * @return osBuildNumber - human entered name of the device
 */
public static String getOSBuildNumber() {
    String osBuildNumber = Build.FINGERPRINT;  //"google/shamu/shamu:5.1.1/LMY48Y/2364368:user/release-keys”
    final String forwardSlash = "/";
    String osReleaseVersion = Build.VERSION.RELEASE + forwardSlash;
    try {
        osBuildNumber = osBuildNumber.substring(osBuildNumber.indexOf(osReleaseVersion));  //"5.1.1/LMY48Y/2364368:user/release-keys”
        osBuildNumber = osBuildNumber.replace(osReleaseVersion, "");  //"LMY48Y/2364368:user/release-keys”
        osBuildNumber = osBuildNumber.substring(0, osBuildNumber.indexOf(forwardSlash)); //"LMY48Y"
    } catch (Exception e) {
        Log.e("getOSBuildNumber", "Exception while parsing - " + e.getMessage());
    }

    return osBuildNumber;
}

这将只返回内部版本号的确切值。请记住,Android SDK 不会这样做。检查 BUILD 类中的以下代码段:

/** A string that uniquely identifies this build.  Do not attempt to parse this value. */
public static final String FINGERPRINT = deriveFingerprint();

/**
 * Some devices split the fingerprint components between multiple
 * partitions, so we might derive the fingerprint at runtime.
 */
private static String deriveFingerprint() {
    String finger = SystemProperties.get("ro.build.fingerprint");
    if (TextUtils.isEmpty(finger)) {
        finger = getString("ro.product.brand") + '/' +
                getString("ro.product.name") + '/' +
                getString("ro.product.device") + ':' +
                getString("ro.build.version.release") + '/' +
                getString("ro.build.id") + '/' +
                getString("ro.build.version.incremental") + ':' +
                getString("ro.build.type") + '/' +
                getString("ro.build.tags");
    }
    return finger;
}

上述方法只是对“deriveFingerprint()”方法中提供的数据进行逆向工程。

于 2015-11-19T18:21:23.283 回答
4

要获取此值,请使用Build.DISPLAY。这是来自 Verizon Note 2 的示例(Android 4.4.2 上的 SCH-I605):KOT49H.I605VRUFND7

要求:API 3 或更高版本。

于 2016-06-07T16:43:50.447 回答
3

我希望它返回您想要的相同值..

String build_number = Build.FINGERPRINT;
System.out.println("Build Number" + build_number);
于 2013-12-20T06:01:31.823 回答
1

使用 Build.DISPLAY 作为内部版本号

于 2016-06-27T10:15:01.147 回答
0
Log.i("TAG", "SERIAL: " + Build.SERIAL);
Log.i("TAG","MODEL: " + Build.MODEL);
Log.i("TAG","ID: " + Build.ID);
Log.i("TAG","Manufacture: " + Build.MANUFACTURER);
Log.i("TAG","brand: " + Build.BRAND);
Log.i("TAG","type: " + Build.TYPE);
Log.i("TAG","user: " + Build.USER);
Log.i("TAG","BASE: " + Build.VERSION_CODES.BASE);
Log.i("TAG","INCREMENTAL " + Build.VERSION.INCREMENTAL);
Log.i("TAG","SDK  " + Build.VERSION.SDK);
Log.i("TAG","BOARD: " + Build.BOARD);
Log.i("TAG","BRAND " + Build.BRAND);
Log.i("TAG","HOST " + Build.HOST);
Log.i("TAG","FINGERPRINT: "+Build.FINGERPRINT);
Log.i("TAG","Version Code: " + Build.VERSION.RELEASE);

嗬它会工作。

于 2018-02-19T16:58:04.683 回答