我试图让广播接收机听互联网连接,然后连接时做一些任务。广播接收机监控互联网连接不工作
当我在我的真实设备上禁用或启用我的WIFI或禁用/启用仿真器中的数据访问时,我没有收到任何通知。操作CONNECTIVITY_CHANGE不再受支持。
public class InternetConnectivityReceiver extends BroadcastReceiver {
Context context;
@Override
public void onReceive(Context context, Intent intent) {
this.context = context;
Log.i(TAG, "Internet Conenction State Changed");
}
}
清单
<application
android:icon="@android:drawable/arrow_down_float"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name=".InternetConnectivityReceiver">
<intent-filter>
<action android:name="android.net.conn.BACKGROUND_DATA_SETTING_CHANGED">
</action>
</intent-filter>
</receiver>
......
</application>
可能的重复:http://stackoverflow.com/questions/3307237/how-can-i-monitor-the-network-connection-status-in-android –
它不是重复的先生。 – MSaudi
你有互联网权限吗? – Lucifer