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?
Go to the Start Menu and select Control Panel. Click the Network and Internet category and then select Networking and Sharing Center. From the options on the left-hand side, select Change adapter settings. Right-click on the icon for Wireless Connection and click enable.
Tap Settings > Wi-Fi. Tap the name of the network, then wait for a login screen to appear. Or tap next to the network's name, then tap Join Network. If prompted, enter a user name and password, enter an email address, or acknowledge terms and conditions.
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)
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