在android的设置中就可以进行更改GPS、网络连接、WIFI、同步等开关,他们是如何是如何实现的呢?
开关枚举值:
替换下面代码中custom中的内容。
private static final int BUTTON_BLUETOOTH = 4;
private static final int BUTTON_BRIGHTNESS = 1;
private static final int BUTTON_GPS = 3;
private static final int BUTTON_SYNC = 2;
private static final int BUTTON_WIFI = 0;
控制开关代码
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:2")); try { PendingIntent.getBroadcast(this, 0, gpsIntent, 0).send(); } catch (CanceledException e) { e.printStackTrace(); }