title: Programmatically turn ON GPS in android
body: <p>Possible duplicates,</p>
  
  <p><a href="https://stackoverflow.com/questions/16752859/how-to-enable-disable-gps-and-mobile-data-in-android-programmatically">How to enable/disable gps and mobile data in android programmatically?</a></p>
  
  <p>I have been seeing people telling that they are able to turn ON the GPS in android programatically. But I'm using the same code and not able to do that. </p>
  
  <p>It is just showing that "Searching for GPS .." but not actually doing it. </p>
  
  <p>Here is the code I'm using,</p>
  
  <pre><code>  //Enable GPS
    Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
    intent.putExtra("enabled", true);
    sendBroadcast(intent);
  
    //Disable GPS
   Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
   intent.putExtra("enabled", false);
   sendBroadcast(intent);
  </code></pre>
  
  <p>I also tried this,</p>
  
  <pre><code>    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);
      }
  </code></pre>
  
  <p>But when I do,</p>
  
  <pre><code> LocationManager manager = (LocationManager) getSystemService( getApplicationContext().LOCATION_SERVICE );
   boolean isGPSEnabled = manager
              .isProviderEnabled(LocationManager.GPS_PROVIDER);
  </code></pre>
  
  <p>it returns me <strong>isGPSEnabled</strong> as false always. If I turn on the gps manually it is returned as true.</p>
  
  <p>Can any body tell me is it possible to ON the GPS like this? If so, where I'm going wrong.</p>