Android Java中的一些使用例子

connectivity= ConnectivityService.getInstance(context);

ServiceManager.addService(Context.CONNECTIVITY_SERVICE,connectivity);

其中ConnectivityService.getInstance(context); 对应于frameworks/base/services/java/com/android/server/ConnectivityService.Java

下面看一下 ConnectivityService.Java中的

for(int netType : mPriorityList) {
switch (mNetAttributes[netType].mRadio) {
case ConnectivityManager.TYPE_WIFI:
Slog.v(TAG, "StartingWifi Service.");
WifiStateTracker wst = newWifiStateTracker(context, mHandler);
WifiService wifiService = newWifiService(context, wst);
ServiceManager.addService(Context.WIFI_SERVICE,wifiService);

wifiService.startWifi();//启动 wifiservice
mNetTrackers[ConnectivityManager.TYPE_WIFI] = wst;
wst.startMonitoring();//启动Monitoring

mWifiEnabler = new WifiEnabler(this,(CheckBoxPreference)findPreference("enable_wifi"));

mNotifyOpenNetworks =(CheckBoxPreference) findPreference("notify_open_networks");

mNotifyOpenNetworks.setChecked(Secure.getInt(getContentResolver(),Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,0) == 1);

 

if (TextUtils.isEmpty(config.deviceAddress)) return true;//红色部分是判断string类型是否为null的API,括号内的参数是string类型。
if (mPeers.get(config.deviceAddress) == null) return true;//mPeers是list类型get是类的成员函数,成员方法,get的依据就是address,譬如:config.deviceAddress

 

posted @ 2016-05-25 16:23  polo2013  阅读(296)  评论(0编辑  收藏  举报