根据WiFiManager可以判断WiFi状态,激活WiFi设置界面的Action为:android.provider.Settings.ACTION_WIFI_SETTINGS
通过LocationManager可以判断GPS状态,激活GPS设置界面的Action为:android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS
示例代码如下:
/** * 检查WiFi和GPS状态 */ private boolean checkWifiAndGPSStatus() { boolean result = true; WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // 判断wifi状态是否开启 if (!wifiManager.isWifiEnabled() && wifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLING) { tv_wifi.setText("WiFi状态:未开启"); result = false; } else { tv_wifi.setText("WiFi状态:已开启"); } // 判断GPS状态 if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { tv_gps.setText("GPS状态:已开启"); } else { tv_gps.setText("GPS状态:未开启"); result = false; } updateConnStatus(); return result; } /** * 设置WiFi */ private void setWiFi() { Intent intent = new Intent( android.provider.Settings.ACTION_WIFI_SETTINGS); startActivityForResult(intent, 0); } /** * 设置GPS */ private void setGPS() { Intent intent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent, 0); }