如何在Android设备中以编程方式获取设备(AOSP)内部版本号?

y1aodyip  于 2023-04-18  发布在  Android
关注(0)|答案(7)|浏览(329)

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

目前,我使用的是“android.os.build”。

ej83mcc0

ej83mcc01#

验证码:
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按上述代码返回

c90pui9n

c90pui9n2#

我使用String Build_Number = Build.DISPLAY;来获取手机设置中显示的版本号

yks3o0rb

yks3o0rb3#

要仅获取设置中“关于设备”中显示的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()”方法中提供的数据进行逆向工程。

sulc1iza

sulc1iza4#

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

jhdbpxl9

jhdbpxl95#

我希望它是返回相同的值,你想要的..

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

um6iljoc6#

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

lhcgjxsq

lhcgjxsq7#

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);

它会工作。

相关问题