Saturday, 8 February 2014

Android Code for Turn On GPS programmatically

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

No comments:

Post a Comment