title: Android 4.1.2 How to turn off GPS programmatically
body: <p>I am trying to switch on GPS by code. The following is the code I've used.</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>The code executing in OnReceive function. What am I doing wrong?</p>