Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i develop GPS application. so i need turn on and off gps automatically.
when my code start gps ones but not turn off automatically.
Please help me.
Posted
Updated 24-Jul-18 21:22pm

Hello,

Please have a look at this[^] thread on StackOverflow.

Please note that some of the solutions recommended on this thread won't work on Android OS post 2.3.

Regards,
 
Share this answer
 
v2
Try this if above code won't work.But you need to remember still there may be some problem on turning gps on/off on some devices.So try what you suit..
Java
//Enable GPS
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);
//Disable GPS
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", false);
sendBroadcast(intent);
 
Share this answer
 
 
Share this answer
 
Comments
groupdatabases 29-Jun-13 7:49am    
i already use this code but not working on samsung galaxy.
Have solution plz give me?
Nirav Prabtani 29-Jun-13 7:52am    
May be this will helpful to you..:)

http://stackoverflow.com/questions/15426144/turning-on-and-off-gps-programmatically-in-android-4-0-and-above
public void turnGPSOn()
{
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);

}

// automatic turn off the gps
public void turnGPSOff()
{
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", false);
sendBroadcast(intent);


}
 
Share this answer
 
Comments
CHill60 27-Mar-15 5:58am    
Please don't answer old questions that have already been adequately resolved.
Member 13924736 25-Jul-18 3:18am    
I have issue on the above code.
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.location.GPS_ENABLED_CHANGE
I put all permissions in my code.Please answer anyone.
Richard MacCutchan 25-Jul-18 3:41am    
Please do not post questions as comments to other (old) questions. Open a new question and provide full details of your problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900