功能描述:Android7.1.2 设置下添加一级菜单[ZedielPcbTest],点击ZedielPcbTest,启动ZedielPcbTest.apk应用。
编译:需要在out目录删除Setttings编译生成的文件,然后remake Settings模块
此功能用到以下类:
packages/apps/Settings/AndroidManifest.xml
packages/apps/Settings/res/values/strings.xml
packages/apps/Settings/src/com/android/settings/Settings.java
packages/apps/Settings/src/com/android/settings/SettingsActivity.java
packages/apps/Settings/src/com/android/settings/ZedielPcbTest.java
功能实现
1.Activity的布局设置在AndroidManifest.xml中实现即可,添加后菜单就可以在:设置下显示 " ZedielPcbTest "
path:packages/apps/Settings/AndroidManifest.xml
<!--Add menu under Settings and open app by zfc 20190525 start-->
<activity android:name="Settings$ZedielPcbTestActivity"
android:label="@string/setting_zedielpcbtest"
android:icon="@drawable/ic_settings_display"
android:taskAffinity="">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- 在category类别中的物理位置(按优先级排序时用到,并不是指第9个位置,数越大优先级越大越靠前) -->
<intent-filter android:priority="15">
<!-- 指定此项在settings中显示 -->
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<!-- 指定此项显示在device这个类别中 -->
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.device" />
<!-- ACTIVITY_ACTION表明 value指向的类是Activity -->
<meta-data android:name="com.android.settings.ACTIVITY_ACTION"
android:value="com.android.settings.HardKey" />
<!-- FRAGMENT_CLASS 表明value指定的类是fragment -->
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
<!-- ZedielPcbTest是具体实现类 -->
android:value="com.android.settings.ZedielPcbTest" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
<!--Add menu under Settings and open app by zfc 20190525 end-->
2.path:packages/apps/Settings/res/values/strings.xml
<string name="setting_zedielpcbtest">ZedielPcbTest</string>
3.path:packages/apps/Settings/src/com/android/settings/Settings.java
//Add menu under Settings and open app by zfc 20190525
public static class ZedielPcbTestActivity extends SettingsActivity { /* empty */ }
4.path:packages/apps/Settings/src/com/android/settings/SettingsActivity.java
// Show only these settings for restricted users
private String[] SETTINGS_FOR_RESTRICTED = {
//wireless_section
WifiSettingsActivity.class.getName(),
Settings.BluetoothSettingsActivity.class.getName(),
Settings.DataUsageSummaryActivity.class.getName(),
Settings.SimSettingsActivity.class.getName(),
Settings.WirelessSettingsActivity.class.getName(),
//device_section
Settings.HomeSettingsActivity.class.getName(),
Settings.SoundSettingsActivity.class.getName(),
Settings.DisplaySettingsActivity.class.getName(),
//Add menu under Settings and open app by zfc 20190525
Settings.ZedielPcbTestActivity.class.getName(),
};
private static final String[] ENTRY_FRAGMENTS = {
WirelessSettings.class.getName(),
WifiSettings.class.getName(),
AdvancedWifiSettings.class.getName(),
SavedAccessPointsWifiSettings.class.getName(),
//Add menu under Settings and open app by zfc 20190525
ZedielPcbTest.class.getName(),
}
5.packages/apps/Settings/src/com/android/settings/ZedielPcbTest.java
/*
* Copyright (C) 2010 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.
*/
package com.android.settings;
import android.content.Context;
import android.os.Build;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import com.android.settings.search.Indexable;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
public class ZedielPcbTest extends SettingsPreferenceFragment implements Indexable{
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Intent intent = new Intent();
ComponentName component = new ComponentName("com.zediel.pcbtest","com.zediel.pcbtest.ZedielTools");
intent.setComponent(component);
startActivity(intent);
finish();
}
@Override
protected int getMetricsCategory() {
return MetricsEvent.DEVICEINFO;
}
}