Android判断网络状态这一应用技巧在实际应中是比较重要的。那么,在Android操作系统中,如何能够正确的判断我们所连接的网络是否断开恩?今天我们就针对这一应用技巧进行一个详细的分析。
1.public class ConnectionChangeReceiver
extends
BroadcastReceiver
2.{
3.@Override
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 thenetwork 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.< actionandroid:name="android.net.conn.CONNECTIVITY_CHANGE"/>
25.< /intent-filter>
26.< /receiver>
Android判断网络状态的具体应用方法就为大家介绍到这里。接下来给大家介绍一款我比较常用的APP测试工具:www.ineice.com