Monday 11 March 2013

Start/Stop GPS Programmatically in Android

private void setGPSOn()
{
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);
}
}

private void setGPSOff(){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if(provider.contains("gps"))
{
//if gps is enabled
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);
}
}

7 comments:

  1. Thank you for sharing excellent informations. Your website is very cool. I'm impressed by the details that youˇ¦ve on this website. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for extra articles. You, my friend, ROCK! I found just the information I already searched everywhere and just could not come across. What a perfect website.

    ReplyDelete
  2. I love your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you? Plz answer back as I'm looking to construct my own blog and would like to know where u got this from. appreciate it

    ReplyDelete
  3. Thank you
    its free Design Theme and its updated me only

    ReplyDelete
  4. Hi, Neat post. There's a problem with your website in internet explorer, would test this… IE still is the market leader and a big portion of people will miss your excellent writing due to this problem.

    ReplyDelete
  5. What’s Taking place i am new to this, I stumbled upon this I've found It absolutely helpful and it has aided me out loads. I hope to give a contribution & help different customers like its aided me. Good job.

    ReplyDelete
  6. I like the helpful information you provide in your articles. I’ll bookmark your weblog and check again here frequently. I'm quite sure I’ll learn many new stuff right here! Best of luck for the next!

    ReplyDelete
  7. Hello my friend! I wish to say that this post is awesome, nice written and include approximately all significant infos. I would like to see more posts like this.

    ReplyDelete