标签:
需要配置权限
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
判断Android的WIFI与GPS状态
private void checkWifiAndGpsStatus() {
boolean result = true;
/* 取得WifiManager与LocationManager */
WifiManager wManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
LocationManager lManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
/* 确认WiFi服务是关闭且不在开启运行中 */
if (!wManager.isWifiEnabled()
&& wManager.getWifiState() != WifiManager.WIFI_STATE_ENABLING) {
tv01.setText("Wifi状态:未启动");
result = false;
} else {
tv01.setText("Wifi状态:已启动");
}
/* 确认GPS是否开启 */
if (!lManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|| !lManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
tv02.setText("GPS状态:未启动");
result = false;
} else {
tv02.setText("GPS状态:已启动");
}
if (result) {
mButton03.setEnabled(true);
} else {
mButton03.setEnabled(false);
}
}
跳转至Wifi设置画面
Intent intent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS); startActivityForResult(intent, 0);
跳转至GPS设置界面
Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent, 0);
判断Android的WIFI与GPS状态,并引导用户前去开启GPS与WIFI设置
标签:
原文地址:http://www.cnblogs.com/huangzx/p/4446482.html