android 判断网络是否断开
引用:http://wang-peng1.iteye.com/blog/557362
publicclassConnectionChangeReceiverextendsBroadcastReceiver
{
@Override
publicvoidonReceive(Contextcontext,Intentintent)
{
ConnectivityManagerconnectivityManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfoactiveNetInfo=connectivityManager.getActiveNetworkInfo();
NetworkInfomobNetInfo=connectivityManager.getNetworkInfo( ConnectivityManager.TYPE_MOBILE);
if(activeNetInfo!=null)
{
Toast.makeText(context,"Active Network Type : "+activeNetInfo.getTypeName(),Toast.LENGTH_SHORT).show();
}
if(mobNetInfo!=null)
{
Toast.makeText(context,"Mobile Network Type : "+mobNetInfo.getTypeName(),Toast.LENGTH_SHORT).show();
}
}
}
<!-- Needed to check when the network connection changes -->
<uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE"/>
<receiverandroid:name="com.blackboard.androidtest.receiver.ConnectionChangeReceiver"
android:label="NetworkConnection">
<intent-filter>
<actionandroid:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
更多相关文章
- android表格效果--ListView隔行变色
- android 界面 滑入 效果
- Android(安卓)之 adapter.notifyDataSetChanged() 无响应
- Android串口通信:基本知识梳理
- Android(安卓)Bander设计与实现 - 设计篇
- android背景与style的设置
- Android(安卓)Studio学习之对文件的基本了解
- Android串口通信:基本知识梳理
- 自定义progressbar 的思路