How to call Wi-Fi settings screen from my application using Android

AndroidWifi

Android Problem Overview


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.

Android Solutions


Solution 1 - Android

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

EDIT: Add the coding line.

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

Solution 2 - Android

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));
}

Solution 3 - Android

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

startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));

Solution 4 - Android

If you want to do it from the xml file:

    <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

Solution 5 - Android

If you're on Android 10, and your goal is to make the user to turn on the WiFi, you don't have to actually navigate to the Wifi settings screen anymore. You can use Settings Pannel

> an API which allows apps to show settings to users in the context of > their app.

Intent panelIntent = new Intent(Settings.Panel.settings_panel_type);
startActivityForResult(panelIntent);

Solution 6 - Android

on button click click Listner

> startActivityForResult(new Intent(Settings.ACTION_WIFI_SETTINGS), 0);

Solution 7 - Android

Here is the code snippet to open wifi settings page

 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);

Solution 8 - Android

I have implemented it like this in my app:

     if (Connectivity.isConnected(this)) {
                SERVER_IP = Connectivity.getIPAddress(true)
            } else {
                SERVER_IP = "Not Connected to Network"
                Snackbar.make(appRoot, "Not Connected to Network", 
                              Snackbar.LENGTH_INDEFINITE)
                              .setAction("Open Settings") {
                   //open network settings
                  startActivity(Intent(Settings.ACTION_WIFI_SETTINGS))
                        }.show()
            }
        }


public static boolean isConnected(Context context) {
		NetworkInfo info = Connectivity.getNetworkInfo(context);
		return (info != null && info.isConnected());
	}

Solution 9 - Android

Not all devices have same Wifi settings package name and class, I use this code to open the wifi settings page on most Android devices :

            try{
                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);
            }catch (ActivityNotFoundException ignored){
                startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
            }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRajendarView Question on Stackoverflow
Solution 1 - AndroidCommonsWareView Answer on Stackoverflow
Solution 2 - Androidkim myounghoView Answer on Stackoverflow
Solution 3 - AndroidVictor Ruiz.View Answer on Stackoverflow
Solution 4 - AndroidkingstonView Answer on Stackoverflow
Solution 5 - AndroidKeselmeView Answer on Stackoverflow
Solution 6 - AndroidRahul PatilView Answer on Stackoverflow
Solution 7 - AndroidJayakrishnanView Answer on Stackoverflow
Solution 8 - AndroidHitesh SahuView Answer on Stackoverflow
Solution 9 - AndroidMaherView Answer on Stackoverflow