从xml开始意图

pso*_*los 1 xml android android-preferences android-intent

我正在尝试让我的首选项可以选择进入系统Wi-Fi设置.

<PreferenceScreen
    android:title="Wifi">
    <intent android:action="android.settings.MAIN"/>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

这会弹出一个菜单,我可以在其中选择一系列活动,wi-fi设置就是其中之一.使用logcat,我能够看到

act=android.intent.action.MAIN 
cmp=com.android.settings/.wifi.WifiSettings
Run Code Online (Sandbox Code Playgroud)

我怎么称呼这个?android文档不是很清楚.我在参考中找到了ACTION_WIFI_SETTINGS,但我无法弄清楚如何直接从意图中调用它.

谢谢

编辑:我试过android:component,但显然不存在

ina*_*ruk 8

尝试使用ACTION_PICK_WIFI_NETWORK直接访问Wi-Fi设置:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >    
    <Preference 
        android:key="key"   
        android:title="WiFi" 
        android:summary="Calls WiFi">           
            <intent android:action="android.net.wifi.PICK_WIFI_NETWORK"/>           
    </Preference>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

PS

该组件由两部分组成:android:targetPackageandroid:targetClass.如果您想知道其他xml属性Intent接受了什么,请转到此处:attrs_manifext.xml

    <!-- The package part of the ComponentName to assign to the Intent, as per
        {@link android.content.Intent#setComponent Intent.setComponent()}. -->
    <attr name="targetPackage" />

    <!-- The class part of the ComponentName to assign to the Intent, as per
        {@link android.content.Intent#setComponent Intent.setComponent()}. -->
    <attr name="targetClass" format="string" />
Run Code Online (Sandbox Code Playgroud)