I am working on an app that uses location.
When starting the app, it verifies if Wireless location is active. If not, a dialog box appears with a button that starts the Intent, Settings.ACTION_SECURITY_SETTINGS to show up the location settings.
I would like to make that task simple for my users and hide unnecessary settings that might make them choose the wrong setting and get the same dialog again.
This application don’t need GPS precision. In some cases, the smartphone may be unable to find GPS signal, or it could take a long time to track location, preventing my application to show results in time, making “Wireless networks” a better option to get location.
Here is some code that I use to test if “Wireless networks” is active and open the settings:
private void checkLocationEnabled() {
String provider = Settings.Secure.getString(getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if (provider == null || !provider.contains("network")) {
// Wireless location not enabled
showDialog();
}
}
private void showDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("No network location. Please, activate this setting in "
+ "Location And Security")
.setCancelable(false)
.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivity(intent);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainActivity.this.finish();
}
});
Dialog dialog = builder.create();
}
How can I filter Settings.ACTION_SECURITY_SETTINGS to show only the Wireless Networks option and remove GPS and all the remaining options in that Intent?
You build your own version of Android that supports this and distribute it in the form of a ROM mod.
Otherwise, you can’t.
AFAIK, that screen does not even have the capability of hiding those things, let alone exposing that capability to third parties via
Intentextras or the like. Moreover, since there are dozens, if not hundreds, of implementations of the Settings app (device manufacturers change this app very frequently), even if this were possible on a few devices, it is unlikely that it would be possible on the rest.