如何使用Android从我的应用程序调用Wi-Fi设置屏幕

时间:2021-08-18 07:31:48

Normally I am getting Wi-Fi setting screen on the emulator by clicking on the Settings > Wireless controls > wifi settings. I need to go directly to the Wi-Fi settings screen from my program when pressing on the Wi-Fi button which I have created. Contacts, call Logs we can handle by using Intent.setData(android.provider.contacts...........). Is there any way to open settings sub menus/menu from an android program ?
Please give me advise or sample code on this.

通常,我通过单击设置>无线控件> wifi设置在模拟器上获得Wi-Fi设置屏幕。按下我创建的Wi-Fi按钮时,我需要从我的程序直接进入Wi-Fi设置屏幕。联系人,调用我们可以使用Intent.setData处理的日志(android.provider.contacts ...........)。有没有办法从Android程序打开设置子菜单/菜单?请给我建议或示例代码。

5 个解决方案

#1


131  

Look at android.provider.Settings for a series of Intent actions you can use to launch various settings screens (e.g., ACTION_WIFI_SETTINGS).

查看android.provider.Settings,了解一系列可用于启动各种设置屏幕的Intent操作(例如,ACTION_WIFI_SETTINGS)。

EDIT: Add the coding line.

编辑:添加编码行。

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

#2


31  

example

ConnectivityManager manager = (ConnectivityManager) 
        getSystemService(MainActivity.CONNECTIVITY_SERVICE);
/*
 * 3G confirm
 */
Boolean is3g = manager.getNetworkInfo(
        ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
/*
 * wifi confirm
 */
Boolean isWifi = manager.getNetworkInfo(
        ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
if (is3g) {
    textView.setText("3G");
} else if (isWifi) {
    textView.setText("wifi");
} else {
    textView.setText("nothing");
    // Activity transfer to wifi settings
    startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
}

#3


23  

Just have to call an intent with a context, try this:

只需要使用上下文调用intent,试试这个:

startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));

#4


9  

If you want to do it from the xml file:

如果要从xml文件中执行此操作:

    <PreferenceScreen
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:key="@string/setting_key"
        android:summary="@string/setting_summary"
        android:title="@string/setting_title" >

        <intent 
            android:action="android.settings.WIRELESS_SETTINGS"/>
    </PreferenceScreen>

This will show an entry in your settings that will call the platform's settings activity

这将在您的设置中显示一个条目,该条目将调用平台的设置活动

#5


0  

Here is the code snippet to open wifi settings page

这是打开wifi设置页面的代码段

 Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings");
        intent.setComponent(cn);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity( intent);

#1


131  

Look at android.provider.Settings for a series of Intent actions you can use to launch various settings screens (e.g., ACTION_WIFI_SETTINGS).

查看android.provider.Settings,了解一系列可用于启动各种设置屏幕的Intent操作(例如,ACTION_WIFI_SETTINGS)。

EDIT: Add the coding line.

编辑:添加编码行。

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

#2


31  

example

ConnectivityManager manager = (ConnectivityManager) 
        getSystemService(MainActivity.CONNECTIVITY_SERVICE);
/*
 * 3G confirm
 */
Boolean is3g = manager.getNetworkInfo(
        ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
/*
 * wifi confirm
 */
Boolean isWifi = manager.getNetworkInfo(
        ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
if (is3g) {
    textView.setText("3G");
} else if (isWifi) {
    textView.setText("wifi");
} else {
    textView.setText("nothing");
    // Activity transfer to wifi settings
    startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
}

#3


23  

Just have to call an intent with a context, try this:

只需要使用上下文调用intent,试试这个:

startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));

#4


9  

If you want to do it from the xml file:

如果要从xml文件中执行此操作:

    <PreferenceScreen
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:key="@string/setting_key"
        android:summary="@string/setting_summary"
        android:title="@string/setting_title" >

        <intent 
            android:action="android.settings.WIRELESS_SETTINGS"/>
    </PreferenceScreen>

This will show an entry in your settings that will call the platform's settings activity

这将在您的设置中显示一个条目,该条目将调用平台的设置活动

#5


0  

Here is the code snippet to open wifi settings page

这是打开wifi设置页面的代码段

 Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings");
        intent.setComponent(cn);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity( intent);