tags:

views:

60

answers:

2

Hello guys,

I'm a beginner android developer.

I want enable and disable GPS with a click of a button, without running this intent:

intente in = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);   

startActivity(in);

that brings me in the setting menu.

Is there a method to enable or disable GPS as in the android "Power Control" widget?

Thanks

+1  A: 

I don't think there is a way to do so. See this question. You can also find a nice example here. Basically what you do is test if GPS is enabled and then navigate user to the appropriate settings page.

The widget you are referring to probably has direct access to the GPS driver. This means that will only work in the device at hand (or in a single family of devices).

kgiannakakis
The widget that I said is in the android system (version 1.6 on forward).There is an application (http://www.siriusapplications.com/powercontrolplus/) that make want I want do, and extend the android power control..my question is: how this persor can manage this??
mist3r0
Since the widget is in the android system it can actually use native code to control the GPS. As for the application, have you tried it out? Does it actually enable/disable the GPS or it just gives you a shortcut? This will be very interesting to know.
kgiannakakis
I've see that this software (http://www.siriusapplications.com/powercontrolplus/) is very similar at the Power Control windget of the android system.For this reason there is a mode for make this!!now maybe I have resolved my problem, I write this code:boolean gpsStatus = locmanager.isProviderEnabled(LocationManager.GPS_PROVIDER);if(!gpsStatus){ Settings.Secure.putString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "network,gps");}
mist3r0
When execute this code the system require tow type of permission, android.permission.WRITE_SECURE_SETTINGS and android.permission.WRITE_SETTINGSbut after I've put this mermissions in my manfest, I've always the folows excemtion: java.lang.SecurityException: Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS. Can you help me??
mist3r0
A: 

The widget that I said is in the android system (version 1.6 on forward). There is an application (siriusapplications.com/powercontrolplus) that make want I want do, and extend the android power control.. my question is: how this persor can manage this?? –

mist3r0
Consider deleting this and adding the information either as a comment or by editing the question
kgiannakakis