关于版本编号:如何以编程方式获取Android设备中的设备(AOSP)Build Number?

How to get device (AOSP) Build Number in Android devices programmatically?

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

System Settings version number on tablet

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


检查此代码..

Build.FINGERPRINT中,您将获得设备的Build Number

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
String mString ="";

    mString.concat("VERSION.RELEASE {" + Build.VERSION.RELEASE +"}");
    mString.concat("
VERSION.INCREMENTAL {" + Build.VERSION.INCREMENTAL +"}");
    mString.concat("
VERSION.SDK {" + Build.VERSION.SDK +"}");
    mString.concat("
BOARD {" + Build.BOARD +"}");
    mString.concat("
BRAND {" + Build.BRAND +"}");
    mString.concat("
DEVICE {" + Build.DEVICE +"}");
    mString.concat("
FINGERPRINT {" + Build.FINGERPRINT +"}");
    mString.concat("
HOST {" + Build.HOST +"}");
    mString.concat("
ID {" + Build.ID +"}");

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

我的设备内部版本号:

My Device Build Number

FINGERPRINT返回上面的代码

enter image description here


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

要求:API 3或更高版本。


要仅获取设置中"关于设备"所示的内部版本号值,我们可以使用以下静态方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
 * 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类中的以下代码段:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/** 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()"方法中提供的数据进行逆向工程。


我希望它返回你想要的相同值。

1
2
String build_number = Build.FINGERPRINT;
System.out.println("Build Number" + build_number);


我使用String Build_Number = Build.DISPLAY;来获取在电话设置中显示的内部版本号


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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);

他会工作的。


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