天天看點

Android - 關于裝置版本号

裝置資訊可以在Settings - About 裡看到

最近想改機器的build number,找到了 build/core/Makefile 裡的定義

# Display parameters shown under Settings -> About Phone
ifeq ($(TARGET_BUILD_VARIANT),user)
  # User builds should show:
  # release build number or branch.buld_number non-release builds

  # Dev. branches should have DISPLAY_BUILD_NUMBER set
  ifeq "true" "$(DISPLAY_BUILD_NUMBER)"
    BUILD_DISPLAY_ID := $(BUILD_ID)-$(BUILD_NUMBER) $(BUILD_KEYS)
  else
    BUILD_DISPLAY_ID := $(BUILD_ID) $(BUILD_KEYS)
  endif
else

  # Non-user builds should show detailed build information
  BUILD_DISPLAY_ID := $(build_desc)

endif      

可看出非user版BUILD_DISPLAY_ID用的是build_desc

可以搜尋到

build_desc := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER) $(BUILD_VERSION_TAGS)      

打開 build/core/build_id.mk ,可以修改BUILD_ID

重新編譯代碼即可

源碼  Build.java  (base/core/java/android/os) 有對這些資訊的引用

想要在apk中取得的話,直接調用Build這個類即可

例如:

Build.DISPLAY  傳回的就是一個String

/** A build ID string meant for displaying to the user */

    public static final String DISPLAY = getString("ro.build.display.id");      

弄一個界面show_info.xml,顯示目前版本的資訊。界面裡放着很多TextView。

MainActivity.java 如下。取出各個狀态資訊

public class MainActivity extends Activity {
    private TextView buildTextView;
    private TextView idTextView;
    private TextView productTextView;
    private TextView boardTextView;
    private TextView deviceTextView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.show_info);
        buildTextView = (TextView) findViewById(R.id.build_number);
        idTextView = (TextView) findViewById(R.id.build_id);
        productTextView= (TextView) findViewById(R.id.product);
        boardTextView= (TextView) findViewById(R.id.board);
        deviceTextView= (TextView) findViewById(R.id.device);
       
        buildTextView.setText(Build.DISPLAY);
        idTextView.setText(Build.ID);
        productTextView.setText(Build.PRODUCT);
        boardTextView.setText(Build.BOARD);
        deviceTextView.setText(Build.DEVICE);
    }
}      

裝上後,在機器上可以看到相關資訊

繼續閱讀