运行以下代码后,如果Gps状态为开启,则关闭,如果为关闭状态,则开启。2.3.6亲测可行
private void toggleGPS() {
Intent gpsIntent = new Intent();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 (CanceledException e) {
e.printStackTrace();
}
}