Android判斷網絡狀態方法詳解

Android 判斷網絡狀態這一應用技巧在實際應中是比較重要的。那麼,在Android操做系統中,如何可以正確的判斷咱們所鏈接的網絡是否斷開恩?今天咱們就針對這一應用技巧進行一個詳細的分析。android

 

1.public class ConnectionChangeReceiver extends網絡

BroadcastReceiver  ide

2.{  工具

3.@Override  測試

4.public void onReceive( Context context, Intent intent )  spa

5.{  操作系統

6.ConnectivityManager connectivityManager =.net

(ConnectivityManager) context.getSystemServiceget

( Context.CONNECTIVITY_SERVICE );  it

7.NetworkInfo activeNetInfo = connectivityManager.

getActiveNetworkInfo();  

8.NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo

( ConnectivityManager.TYPE_MOBILE );  

9.if ( activeNetInfo != null )  

10. {  

11.st.makeText( context, "Active Network Type : " +

  tiveNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show();  

12. }  

13. mobNetInfo != null )  

14. {

15.st.makeText( context, "Mobile Network Type : " +

  bNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show();  

16. }

17.}  

18.}  

19.< !-- Needed to check when the network connection changes -->  

20.< uses-permission android:name="android.permission.

ACCESS_NETWORK_STATE"/>  

21.< receiver android:name="com.blackboard.androidtest.

receiver.ConnectionChangeReceiver"  

22.android:label="NetworkConnection">  

23.< intent-filter>  

24.< action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>  

25.< /intent-filter>  

26.< /receiver>

 

Android判斷網絡狀態的具體應用方法就爲你們介紹到這裏。接下來給你們介紹一款我比較經常使用的APP測試工具:www.ineice.com

相關文章
相關標籤/搜索