Reprinted from: http://blog.csdn.net/etzmico/article/details/7200470
If the current GPS status is enabled, it is disabled after the code is run; otherwise, it is enabled ~
The Code is as follows:
Intent gpsintent = new intent (); <br/> gpsintent. setclassname ("com. android. settings ", <br/>" com. android. settings. widget. settingsappwidgetprovider "); <br/> gpsintent. addcategory ("android. intent. category. alternative "); <br/> gpsintent. setdata (URI. parse ("custom: 3"); <br/> try {<br/> pendingintent. getbroadcast (this, 0, gpsintent, 0 ). send (); <br/>}catch (canceledexception e) {<br/> E. printstacktrace (); <br/>}
To make it easier to see the effect, you can add the finish (); Method in oncreate, open the system GPS settings page, and run the Code, so that you can see the changes in the GPS switch.
Engineering Resources: http://download.csdn.net/detail/etzmico/4021034