Saturday, 5 October 2013

Performing Operation On GPS (like checking gps connection,turn on gps,turn off gps)

Hello Friends

On today's post you will find  all the operations  regarding GPS. In that you handle your GPS connection and perform operation  Pro-grammatically.

A)First, find solution of Checking the GPS Connection Pro-grammatically with the few simple steps:-

  public Boolean checkGPSProvider() {
LocationManager service = (LocationManager) _context
.getSystemService(_context.LOCATION_SERVICE);
boolean enabled = service
.isProviderEnabled(LocationManager.GPS_PROVIDER);

return enabled;
}

B)Next, You find how to Automatically Turn On GPS Connection.:-

  public void turnGPSOn() {
String provider = Settings.Secure.getString(
_context.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"));
_context.sendBroadcast(poke);
}

}

C)Last, You find  how to Automatically Turn Off GPS Connection.:-

  public void turnGPSOff() {
String provider = Settings.Secure.getString(
_context.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"));
_context.sendBroadcast(poke);
}
}

For download File....Click Here

Download this file,Copy it into your project and just call this above method..it works..

Thanks..

0 comments:

Post a Comment

 

Copyright © Unique Android Tutorial.. Design by Free CSS Templates | Blogger Theme by BTDesigner | Powered by Blogger