Reputation: 41
I want to switch on GPS and WiFi by code forcefully without going to setting, so I any suggestions as to how to achieve this in ICS .
String provider = Settings.Secure.getString(getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if (!provider.contains("gps")) { // if gps is disabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
sendBroadcast(poke);
}
This code is working fine in 2.1 but in ICS it isn't.
Upvotes: 3
Views: 354
Reputation: 855
To enable GPS, there is no API provided by Android because of Security.So you will not be able to turn ON GPS without user intervention.
TO enable Wi-Fi,
WifiManager wifiManager = new WifiManager()
if(wifiManager.isWifiEnabled())
wifiManager.setWifiEnabled(false);
Choose whatever you want, either to set it ON or OFF.
Upvotes: 1
Reputation: 172
Please use this code for manual enable through setting because due to security reason in ics this features has been removed.
Intent callGPSSettingIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(callGPSSettingIntent);
Upvotes: 2
Reputation: 2604
The code which you wrote in the question was working fine previously, But since it was security loophole, Android developer has fixed it now a days.
So even if you use the above code, it gives GPS blinking animation, but in real it is not working at all. You can see the GPS Blinking even after you remove you application from the device.
Upvotes: 0