Android examples for Hardware:Gps
turn GPS On
import android.content.Context; import android.content.Intent; import android.net.Uri; import android.provider.Settings; public class Main { public static void turnGPSOn(Context context) { Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE"); intent.putExtra("enabled", true); context.sendBroadcast(intent);// w ww . java 2s . co m 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); } } }