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 Enable or Disable Wi-Fi Following is the code snippet to enable a Wi-Fi in android application by using setWifiEnabled() method. WifiManager wmgr = (WifiManager)Context. getSystemService(Context. WIFI_SERVICE);
Click Start, Settings, Network & Internet, and then select the Wi-Fi entry on the left list. Click the Advanced options entry below the last wireless network in the list.
setWifiEnabled(false); So you can enable or disable WiFi using WifiManger class. You need to add extra permissions in AndroidManifest. xml to enable or disable Wifi.
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));
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)); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With