Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,802,856 Members 38,668 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Enable GPS

Tip us?
Member - OP
Thanks Meter 1
Posts: 30
Join Date: Jul 2010
Question [Q] Enable GPS

Hello Guys,

I'm a beginner android programmer.

I want to active directly GPS, same the Power Control android Widget.

I've saw this code of android kernel (

I nedd to enable or disable GPS, when i click a button.

I've write this code:

booelan gpsStatus = locmanager.isProviderEnabled(LocationManager.GPS_P ROVIDER);


Settings.Secure.setLocationProviderEnabled(getCont entResolver(), LocationManager.GPS_PROVIDER, true);


and I've put into manifest file the following permissions:

<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>

<uses-permission android:name="android.permission.WRITE_SECURE_SETT INGS"></uses-permission>

but when execute my code, the system send me this error:

java.lang.SecurityException: Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS

but I've already inser into the manifest file this permission!!!

Can you help me?? Please, it's very important!!!

Thank you!
Gene Poole
(Last edited by Gene Poole; 26th October 2010 at 02:17 PM.)
Recognized Contributor
Thanks Meter 551
Posts: 1,667
Join Date: Jul 2010
Location: Brighton IL
Some phones disable WRITE_SECURE_SETTINGS in their "default.prop" file which is stored in the boot partition so you need root and a lot of other utilities to change it. Here is is on the HTC Aria:

Member - OP
Thanks Meter 1
Posts: 30
Join Date: Jul 2010
I've tested this code on HTC DESIRE with root permission, but this code don't work!!
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes