7

I have an app which almost always needs to know the user location.

When I need to access a location, I do this:

final AlertDialog.Builder builder = new AlertDialog.Builder(
                        MapScreen.this);
builder.setTitle("MyAppName");
builder.setMessage("The location service is off. Do you want to turn it on?");
                builder.setPositiveButton("Enable location",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(
                                    final DialogInterface dialogInterface,
                                    final int i) {
                                startActivity(new Intent(
                                        android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                            }
                        });
builder.setNegativeButton("Continue without location", null);
builder.create().show();

However, the GPS gives me some info that isn't always precise enough. Wi-Fi always gives me enough precission, so I want to ask the user to turn on the Wi-Fi the same way I ask them to turn on the location. I do not want to just turn it on, I want the user to be notified about it, and to manually enable it.

Is there any Intent to bring the WiFi menu to the user?

Charlie-Blake
  • 10,832
  • 13
  • 55
  • 90

3 Answers3

14

Following intent shows the wireless settings such as Wi-Fi, Bluetooth and Mobile networks:

startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));

For the complete list of Settings: https://developer.android.com/reference/android/provider/Settings.html

For the documentation on the startActivity method: https://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent)

(keep in mind startActivity is just throw and forget, if you want to capture the response of what the user did out there you could instead call startActivityForResult, probably not needed in this case)

T_D
  • 3,241
  • 3
  • 17
  • 24
4

You can try

Intent i = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
                startActivity(i);
Alexis C.
  • 91,686
  • 21
  • 171
  • 177
4

The previous answers were quotting the "Settings.ACTION_WIRELESS_SETTINGS", but it is too general, as it is going to open the settings of the general wireless connection while the question is about wifi only. I'm using "Settings.ACTION_WIFI_SETTINGS" as follows

Intent turnWifiOn = new Intent(Settings.ACTION_WIFI_SETTINGS);
startActivity(turnWifiOn);

Note: It's not going to open just a dialog, but an activity instead.

Mário Augusto
  • 426
  • 5
  • 8