Tuesday, July 3, 2012

Launching settings from a button

I was recently working on an Android tablet project that needs to detect connectivity to a network. If the user wasn't connected to the Internet, I would throw up a dialog box telling them to connect. I decided to take this one step further and take them to the setting screen that would allow them to connect to wifi.

So to do this, I needed to send an intent that would launch settings. Easy enough.The Android snippet below does that.


Intent intent = new Intent(Intent.ACTION_MAIN);
 intent.setClassName("com.android.settings", "com.android.settings.Settings");
startActivity(intent);


Now that's ok, but it takes the user to settings main screen. Which is nice but a better way to do that is to send them directly to the wireless settings screen.  This can be done using the code below.


Intent intent =new Intent(Settings.ACTION_WIRELESS_SETTINGS);
startActivity(intent);



No comments:

Post a Comment