首先獲取系統的連線服務:
private connectivitymanager connectivitymanager;
connectivitymanager = (connectivitymanager) mcontext
然後獲取當前手機的聯網的狀態:
gprs網路:
connectivitymanager.getactivenetworkinfo().gettype() == connectivitymanager
.type_mobile
wifi網路:
connectivitymanager.getactivenetworkinfo().gettype() == connectivitymanager.type_wifi
還有斷網的狀態:
networkinfo gprs =connectivitymanager.getnetworkinfo (connectivitymanager.type_mobile);
networkinfo wifi =connectivitymanager.getnetworkinfo (connectivitymanager.type_wifi);
(gprs == null || !gprs.isconnected()) && (wifi == null || !wifi.isconnected())
根據不同的網路狀態做出對應的處理。 Android網路連線狀態
實習告一段落,回校準備畢業答辯,享受最後的大學生活。開發android應用程式,在需要進行連線網路時,如果沒有可用的網路連線,提醒手機使用者沒有可用的連連線,讓使用者有比較好的體驗。驗證 如下 1 首先獲得所有的網路連線manager.getallnetworkinfo 2 在迴圈判斷網路連線是否可...
Android 檢測網路連線狀態
檢測是否接入網際網路 connectivitymanager cm connectivitymanager context.getsystemservice context.connectivity service networkinfo activenetwork cm.getactivenetw...
IOS檢測網路連線狀態
然後將reachability.h 和 reachability.m 加到自己的專案中,並引用systemconfiguration.framework,就可以使用了。reachability 中定義了3種網路狀態 the network state of the device for reacha...