需求是Settings > System下增加一个about phone,再点进去显示硬件版本信息。
1.settings_enums中增加定义。
//frameworks\base\core\proto\android\app\settings_enums.proto
SETTINGS_HW_CATEGORY = 1846;
2.找到System界面对应的xml文件,添加about phone的定义。
//vendor\mediatek\proprietary\packages\apps\MtkSettings\res\xml\system_dashboard_fragment.xml
<Preference
android:key="about_phone_settings"
android:title="@string/about_settings"
android:icon="@drawable/ic_homepage_about"
android:order="-230"
android:fragment="com.android.settings.system.AboutPhoneSettings" />
3.定义硬件版本信息的xml文件。
// vendor\mediatek\proprietary\packages\apps\MtkSettings\res\xml\about_phone_setting.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference
app:key="hw_version"
app:title="HW version"
app:summary="ABC"/>
</PreferenceScreen>
4.新建一个显示硬件版本信息的fragment。这里的fragment必须继承DashboardFragment ,不然初始化会有问题,由于不需要其他功能,继承后重写3个函数即可。
新建文件有一点比较坑的是,不能自动import R文件等。
//vendor\mediatek\proprietary\packages\apps\MtkSettings\src\com\android\settings\system\AboutPhoneSettings.java
package com.android.settings.system;
import android.content.Context;
import android.os.Bundle;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import android.app.settings.SettingsEnums;
public class AboutPhoneSettings extends DashboardFragment {
private static final String TAG = "AboutPhoneSettings";
@Override
public int getMetricsCategory() {
return SettingsEnums.SETTINGS_HW_CATEGORY;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.about_phone_setting;
}
}
网友评论