<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> : NETWORK 和 GPS 权限
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
(LocationManager) Android002.this.getSystemService(Context.LOCATION_SERVICE);
getAllProviders()
getBestProvider(criteria, false)
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);//设置查询精度的高低
criteria.setPowerRequirement(Criteria.POWER_LOW);//设置消耗级别高低
criteria.setAltitudeRequired(false);//海拔
criteria.setSpeedRequired(false);//速度
criteria.setCostAllowed(false);//会不会产生费用
根据Criteria这个类设置的要求,选出最好的provider
<uses-permission android:name="android.permission.INTERNET"/> 访问网络的权限
//访问指定的网页
String path = "http://192.168.0.99:8080/my/index.jsp";//post
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", "admin"));
HttpPost request = new HttpPost(path);
request.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
HttpResponse response = new DefaultHttpClient().execute(request);
boolean flag= false;
if(response.getStatusLine().getStatusCode() != 404){
flag = Boolean.parseBoolean(EntityUtils.toString(response.getEntity()).trim());
}
wifi权限:
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
跟LocationManager差不多:
wifiManager = (WifiManager)MainActivity.this.getSystemService(Context.WIFI_SERVICE);
getWifiState():当前wifi的状态
setWifiEnabled():设置wifi的状态,true为打开,false为关闭