引用: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>

更多相关文章

  1. android表格效果--ListView隔行变色
  2. android 界面 滑入 效果
  3. Android(安卓)之 adapter.notifyDataSetChanged() 无响应
  4. Android串口通信:基本知识梳理
  5. Android(安卓)Bander设计与实现 - 设计篇
  6. android背景与style的设置
  7. Android(安卓)Studio学习之对文件的基本了解
  8. Android串口通信:基本知识梳理
  9. 自定义progressbar 的思路

随机推荐

  1. android asyncTask的使用
  2. android 系统内存显示
  3. Android开发学习——android与服务器端数
  4. android 打水印
  5. android ksoap2调用.net Webservice 方法
  6. 关于build.gradle的写法
  7. Android Skia和2D图形系统
  8. Android 获取时间戳 和时间戳转日期
  9. android ScreenCapture
  10. Android 之Java动态生成View