如何启动Android SubSettings片段? [英] How to launch an Android SubSettings Fragment?

查看:337
本文介绍了如何启动Android SubSettings片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如何启动用户设置?它没有实现为自己的Activity,所以我不确定如何启动它.

For example, how do I launch User Settings? It's not implemented as its own Activity, so I'm not sure how to start it.

以下是一些其他类似的问题,但这些问题更笼统或更具体.我的问题是关于启动任意SubSettings片段.

Below are some other similar questions but these are either more general or more specific. My question is about starting an arbitrary SubSettings fragment.

如何从PreferenceActivity?

仅显示Android 3上的无线系统设置

推荐答案

您可以通过启动SubSettings Activity并包含适当的完整内容,包括:android:show_fragment 来启动大多数Android设置子屏幕.现有的Android PreferenceFragment子类的限定类名.

You can launch most Android Settings sub-screens by starting the SubSettings Activity and including the :android:show_fragment extra with the appropriate fully-qualified class name of an existing Android PreferenceFragment subclass.

例如,要启动UserSettings:

For example, to start UserSettings:

adb shell am start -n com.android.settings/com.android.settings.SubSettings -e :android:show_fragment com.android.settings.users.UserSettings

要启动DeviceInfoSettings,请执行以下操作:

To start DeviceInfoSettings:

adb shell am start -n com.android.settings/com.android.settings.SubSettings -e :android:show_fragment com.android.settings.DeviceInfoSettings

这些示例使用"adb shell am start",但是原则上您可以在Java代码中调用它们(不幸的是,您需要使用系统密钥签名,否则会收到SecurityException).请注意,此额外功能的键在其前面有一个冒号.要查找其他设置,请检出Android源代码并在程序包/应用程序/设置中查找PreferenceFragment的子类.

These examples use 'adb shell am start', but in principle you could invoke these in Java code ( Unfortunately you need to be signed with the system key, otherwise you get a SecurityException). Notice that the key for this extra has a colon at the front of it. To find other Settings, checkout the Android source and look for subclasses of PreferenceFragment in the packages/apps/Settings.

在Froyo和以前,情况有所不同.那时,活动用于实现设置"子屏幕,因此可以通过使用ComponentName或action String调用startActivity()的常用方法直接将其启动到子屏幕(例如SoundAndDisplaySettings).此机制仍适用于某些设置"子屏幕.例如,要调出wifi选择器,您可以使用

The situation was different in Froyo and before. In those days Activities were used to implement Settings sub-screens, so one could launch directly into a sub-screen (for example SoundAndDisplaySettings) by the usual method of calling startActivity() with a ComponentName or action String. This mechanism still works for some Settings sub-screens. For example, to bring up a wifi picker, you can use

adb shell am start -a android.net.wifi.PICK_WIFI_NETWORK

这篇关于如何启动Android SubSettings片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆