<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />        <receiver android:name=".NetworkConnectionChangeReceiver"             android:enabled="true"              android:exported="false">            <intent-filter>                <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>            </intent-filter>        </receiver>




import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.net.ConnectivityManager;import android.net.NetworkInfo;import android.net.NetworkInfo.State;public class NetworkConnectionChangeReceiver extends BroadcastReceiver {  @Override  public void onReceive(Context context, Intent intent) {    Intent myIntent = new Intent(context, WAMPClient.class);        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);    NetworkInfo info = cm.getActiveNetworkInfo();        if (null != info) {      State state = info.getState();      if (State.CONNECTED == state) {        // connected to network        context.startService(myIntent);      }    }    else {
      // network connection lost      context.stopService(myIntent);    }  }}
   

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android开发—弹出列表、单选、多选框
  2. Android获取传感器列表
  3. Android软硬整合技术(HAL&Framework):高阶
  4. Android GPS 获得 经纬度 并得到该 坐标
  5. Android---45---使用AIDL Service传递复
  6. Android开发网站
  7. Android(安卓)OOM 解决方案
  8. Android事件拦截与处理
  9. Android使用Application代替全局变量
  10. Android下进行 Facebook 分享