Android使用广播监听网络状态变化 一直收到系统广播

来源:互联网 发布:知乎 台北君悦酒店闹鬼 编辑:程序博客网 时间:2024/05/19 08:24

Android使用广播监听网络状态变化 一直收到系统广播


在清单文件中注册了监听网络连接的广播<receiver android:name="com.erlinyou.receivers.InternetChangeListener">    <intent-filter>        <action android:name="android.net.conn.CONNECTIVITY_CHANGE"></action>    </intent-filter></receiver>在OnReceive方法中 打印了Log  LogCat中在一直打印OnReceive @Overridepublic void onReceive(Context context, Intent intent) {    Log.d("!!", "onReceive");}
在 onReceive里加以一条判断搜索
String action = intent.getAction();
if(TextUtils.equals(action, CONNECTIVITY_CHANGE_ACTION)){//网络变化的时候会发送通知
            Log.i(TAG, "网络变化了");
            return;
        }

0 0
原创粉丝点击