Intent go to setting wifi

Is there a way to open Wifi activity in android and get a result for successful connection in android

The user then selects a wifi network ,connects to it and the wifi setting activity closes and the user lands back into my application. How do I achieve this?

But this doesn’t answer my question of how to return back to the activity by connecting to a particular network

2 Answers 2

android.provider.Settings gives Intent actions you can use to launch various settings screens (e.g., ACTION_WIFI_SETTINGS).

To work with button you must write:

yourButton.setOnClickListener(new View.OnClickListener() < @Override public void onClick(View view) < Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS); startActivity(intent); >>); 

For getting wifi connected callback, you must put permissions in manifest:

And put this code in activity onCreate or some method:

ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkRequest.Builder builder = new NetworkRequest.Builder(); connectivityManager.registerNetworkCallback(builder.build(), new ConnectivityManager.NetworkCallback() < @Override public void onAvailable(Network network) < //Do your work here or restart your activity Intent i = new Intent(this, MyActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(i); >@Override public void onLost(Network network) < //internet lost >>); 

Источник

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

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.

Читайте также:  Обновить драйвер вайфай асус

9 Answers 9

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.

to be more specific, android.app.activity.startActivity(new android.content.Intent.Intent(android.provider.settings.Settings.ACTION_WIFI_SETTINGS)); or with proper using, startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

@Mr_and_Mrs_D: Possibly. I can see where the Settings app might not handle these Intents properly when the Settings app is already in memory, but I haven’t tried this specific scenario.

to open general wireless settings use this: startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));

@patrickjason91: «if it will be possible that the app’s Intent call can control some configuration to how the WiFi settings, or to any other settings screen in general, will display?» — not in general, and not using any documented extras.

Источник

how to open configure portable Wi-Fi hotspot setting by onclick?

how to open the following directory:settings/wireless and networks/Tethering and portable hotspot/portable Wi-Fi hotspot settings/configure portable Wi-Fi hotspot/ on button click? i want to achieve this using onClick method not id method. below is my code

 public void togglewifi(View view)

6 Answers 6

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

This opens the Tethering screen. Is there another way to open the WiFi Hotspot screen only? I know it’s possible because SHAREit does that.

In case any one lands here like me, on Android 8, I used this to open up the setup Hotspot page itself.

public static final String SETTINGS_PACKAGE = "com.android.settings"; public static final String HOTSPOT_SETTINGS_CLASS = "com.android.settings.Settings$TetherWifiSettingsActivity"; private void launchHotspotSettings()

Works on my device. Let me know if it works on yours. After a bit of research I realized that this class changes per device brand. Eg. For Samsung, use

public static final String HOTSPOT_SETTINGS_CLASS = "com.android.settings.Settings$WifiApSettingsActivity"; 

By the way @Drew answer still works on Android 8.

Читайте также:  Смарт тв вай фай модуль

Источник

Launching mobile network settings screen programmatically

I’ve tried this myself and couldn’t get it to work, the closest thing that I found that you can do is to use this Intent: startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS)); It brings up the overall network settings and from there the user can go to mobile networks

6 Answers 6

They won’t work because there was a bug that was fixed I think in 2.3.

You can bypass this using (for NETWORK_OPERATOR_SETTINGS)

Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClassName("com.android.phone", "com.android.phone.NetworkSetting"); startActivity(intent); 

Replace NetworkSetting with Settings for DATA_ROAMING_SETTINGS

there’s another similar solution described in Error opening mobile network settings menu

I recently tested this and it seems that this workaround is still necessary up to API level 15. Since API level 16 the intents in the question seem to work correctly.

Thanks @Zharf. this was what i was looking for. intent.setClassName(«com.android.phone», «com.android.phone.Settings»);

@ShirishHerwade I’m not aware of them, but the problem here was that the regular intent action constants didn’t work in 2.2 and earlier because of the linked bug. Frankly this shouldn’t be something that people should worry about these days because no one should be targeting pre-ICS stuff 🙂

@ShirishHerwade huh, well I just tested this on my API 15 device actually and it seems that the Settings.ACTION_ constants still aren’t working there. I guess you should use ACTION_MAIN then. Since API 16 the Settings.ACTION_ constants seem to work.

public class SettingsScreen < protected static void _showSettingScreen(String intentStr) < try < Intent intent = new Intent(intentStr); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Reference.getAppContext().startActivity(intent); >catch (Exception e) > public static void showSettingScreen() < _showSettingScreen("android.settings.SETTINGS"); >public static void showAPNScreen() < _showSettingScreen("android.settings.APN_SETTINGS"); >public static void showLocationScreen() < _showSettingScreen("android.settings.LOCATION_SOURCE_SETTINGS"); >public static void showSecurityScreen() < _showSettingScreen("android.settings.SECURITY_SETTINGS"); >public static void showWifiScreen() < _showSettingScreen("android.settings.WIFI_SETTINGS"); >public static void showBluetoothScreen() < _showSettingScreen("android.settings.BLUETOOTH_SETTINGS"); >public static void showDateScreen() < _showSettingScreen("android.settings.DATE_SETTINGS"); >public static void showSoundScreen() < _showSettingScreen("android.settings.SOUND_SETTINGS"); >public static void showDisplayScreen() < _showSettingScreen("android.settings.DISPLAY_SETTINGS"); >public static void showApplicationScreen() < _showSettingScreen("android.settings.APPLICATION_SETTINGS"); >public static void showNetworkSettingScreen() < showDataRoamingScreen(); >public static void showNetworkOperatorScreen() < if(Reference.getSystemOptions().VERSION_SDK_INT >15) < _showSettingScreen("android.settings.NETWORK_OPERATOR_SETTINGS"); >else < Intent intent=new Intent(android.provider.Settings.ACTION_SETTINGS); intent.setClassName("com.android.phone", "com.android.phone.NetworkSetting"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Reference.getAppContext().startActivity(intent); >> public static void showDataRoamingScreen() < if(Reference.getSystemOptions().VERSION_SDK_INT >15) < _showSettingScreen("android.settings.DATA_ROAMING_SETTINGS"); >else < Intent intent=new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS); ComponentName cName = new ComponentName("com.android.phone","com.android.phone.Settings"); intent.setComponent(cName); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Reference.getAppContext().startActivity(intent); >> public static void showDataMobileScreen() < if(Reference.getSystemOptions().VERSION_SDK_INT >15) < Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);//android.provider.Settings.ACTION_SETTINGS //Intent.ACTION_MAIN intent.setClassName("com.android.settings", "com.android.settings.Settings$DataUsageSummaryActivity"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Reference.getAppContext().startActivity(intent); >else < showDataRoamingScreen(); >> public static void showNotificationScreen() < _showSettingScreen("android.settings.NOTIFICATION_SETTINGS"); >public static void showBatterySaverScreen() < _showSettingScreen("android.settings.BATTERY_SAVER_SETTINGS"); >public static void showNfcScreen() < _showSettingScreen("android.settings.NFC_SETTINGS"); >public static void showInternalStorageScreen() < _showSettingScreen("android.settings.INTERNAL_STORAGE_SETTINGS"); >public static void showDictionarySettingScreen() < _showSettingScreen("android.settings.USER_DICTIONARY_SETTINGS"); >public static void showManageApplicationsScreen() < _showSettingScreen("android.settings.MANAGE_APPLICATIONS_SETTINGS"); >public static void showManageAllApplicationsScreen() < _showSettingScreen("android.settings.MANAGE_ALL_APPLICATIONS_SETTINGS"); >public static void showMemoryCardScreen() < _showSettingScreen("android.settings.MEMORY_CARD_SETTINGS"); >public static void showAirPlaneScreen() < if(Reference.getSystemOptions().VERSION_SDK_INT >16) < if(Reference.getSystemOptions().BRAND.equalsIgnoreCase("Lenovo")) < showSettingScreen(); >else < _showSettingScreen("android.settings.WIRELESS_SETTINGS"); >> else < _showSettingScreen("android.settings.AIRPLANE_MODE_SETTINGS"); >> public static void showWirelessScreen() < _showSettingScreen("android.settings.WIRELESS_SETTINGS"); >public static void showWifiScreenSafe() < 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); Reference.getAppContext().startActivity(intent); >catch (Exception e) <> > > 

Источник

Оцените статью
Adblock
detector