修改设置->关于手机->法律信息 下有一些Item,如开放源代码许可、Google法律信息等,这里分析的是Android 4.4的代码
如下图所示,想添加“Google法律信息”选项
查看Settings的源码在/Settings/src/com/android/settings/DeviceInfoSettings.java文件初始化时有这样一段代码
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.device_info_settings);
//............................................省略
/*
* Settings is a generic app and should not contain any device-specific
* info.
*/
final Activity act = getActivity();
// These are contained in the "container" preference group
PreferenceGroup parentPreference = (PreferenceGroup) findPreference(KEY_CONTAINER);
Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TERMS,
Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_LICENSE,
Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_COPYRIGHT,
Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TEAM,
Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
//..............................................省略
}
看加载的资源文件device_info_settings.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project Licensed under the
Apache License, Version 2.0 (the "License"); you may not use this file except
in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the License. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/about_settings">
<!-- System update settings - launches activity -->
<PreferenceScreen android:key="system_update_settings"
android:title="@string/system_update_settings_list_item_title"
android:summary="@string/system_update_settings_list_item_summary">
<intent android:action="android.settings.SYSTEM_UPDATE_SETTINGS" />
</PreferenceScreen>
<PreferenceScreen android:key="software_update"
android:title="@string/software_update">
</PreferenceScreen>
<PreferenceScreen android:key="mdm_fumo"
android:title="@string/software_update">
</PreferenceScreen>
<!-- MOTA -->
<PreferenceScreen android:key="mtk_system_update">
<intent android:action="com.mediatek.intent.System_Update_Entry" />
</PreferenceScreen>
<!-- software update service -->
<PreferenceScreen android:key="scomo"
android:title="@string/scomo_settings_title" android:summary="@string/software_updates_scomo_summary">
<intent android:action="android.intent.action.MAIN"
android:targetPackage="com.mediatek.dm" android:targetClass="com.mediatek.dm.scomo.DmScomoActivity" />
</PreferenceScreen>
<PreferenceScreen android:key="mdm_scomo"
android:summary="@st