功能描述: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
android:label="@string/setting_zedielpcbtest"
android:icon="@drawable/ic_settings_display"
android:taskAffinity="">
android:value="com.android.settings.category.device" />
android:value="com.android.settings.ZedielPcbTest" />
android:value="true" />
2.path:packages/apps/Settings/res/values/strings.xml
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;
}
}