How can I call the Wi-Fi settings screen from my application using Android

Usually I get the Wi-Fi settings screen on the emulator by clicking on Settings > Wireless controls > wifi settings . I need to go directly to the Wi-Fi settings screen from my program by clicking on the Wi-Fi button that I created. Contacts, call logs that we can process using Intent.setData (android.provider.contacts ...........). Is there a way to open a submenu / settings menu from an Android program?
Please give me advice or sample code.

+64
android wifi
Feb 23 '10 at 13:12
source share
6 answers

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

EDIT: Add an encoding string.

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

+137
Feb 23 '10 at 14:25
source share

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)); } 
+31
Jan 12 '11 at 12:05
source share

You just need to name the intent context, try the following:

 startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); 
+23
04 Sep '13 at 15:47
source share

If you want to do this from an 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 the settings that trigger the activity of the platform settings.

+10
Nov 05 '11 at 18:56
source share

Here is a snippet of code to open the 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); 
+1
Jul 14 '16 at 16:47
source share

on the button, click the "List" button

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

0
Dec 04 '18 at 6:38
source share



All Articles