標籤:
Android 判斷網路狀態這一應用技巧在實際應中是比較重要的。那麼,在Android作業系統中,如何能夠正確的判斷我們所串連的網路是否斷開恩?今天我們就針對這一應用技巧進行一個詳細的分析。
1.public class ConnectionChangeReceiver extends
BroadcastReceiver
2.{
[email protected]
4.public void onReceive( Context context, Intent intent )
5.{
6.ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService
( Context.CONNECTIVITY_SERVICE );
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
Android判斷網路狀態方法詳解