26.MTK Android 设置下添加一级菜单[ZedielPcbTest]

功能描述:Android7.1.2 设置下添加一级菜单[ZedielPcbTest],点击ZedielPcbTest,启动ZedielPcbTest.apk应用。


此功能用到以下类:

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.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>
  <intent-filter android:priority="15">
    <action android:name="com.android.settings.action.SETTINGS" />
  </intent-filter>
  <meta-data android:name="com.android.settings.category"
    android:value="com.android.settings.category.device" />
  <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
    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;
  }

}

猜你喜欢

转载自www.cnblogs.com/cyqx/p/10935249.html