When studying android gps, I found that the android system hides the interface for gps switch operations, and I don't know why, I personally think it may be because all the programs are operating on the gps switch, leading to confusion! However, I still saw a method to operate on the gps switch using code on the Internet. Contribute!
========================================================== ========================================================== ====
Directly run the Code:
Private voidtoggleGPS (){
IntentgpsIntent = newIntent ();
GpsIntent. setClassName ("com. android. settings ",
"Com. android. settings. widget. SettingsAppWidgetProvider ");
GpsIntent. addCategory ("android. intent. category. ALTERNATIVE ");
GpsIntent. setData (Uri. parse ("custom: 3 "));
Try {
PendingIntent. getBroadcast (this, 0, gpsIntent, 0). send ();
}
Catch (CanceledExceptione ){
E. printStackTrace ();
}
}
From chenghai2011