Android 用于监视internet连接的广播接收器不工作
我正试图使广播接收器,听互联网连接,然后做一些任务时,连接 当我在真实设备上禁用或启用WIFI或在emulator中禁用/启用数据访问时,我不会收到任何通知。不再支持操作更改Android 用于监视internet连接的广播接收器不工作,android,broadcastreceiver,Android,Broadcastreceiver,我正试图使广播接收器,听互联网连接,然后做一些任务时,连接 当我在真实设备上禁用或启用WIFI或在emulator中禁用/启用数据访问时,我不会收到任何通知。不再支持操作更改 public class InternetConnectivityReceiver extends BroadcastReceiver { Context context; @Override public void onReceive(Context context, Intent intent) { thi
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>
......
说:
背景数据设置已更改
此常量已弃用。从冰淇淋三明治开始,供应
背景数据取决于几个综合因素,这
广播不再发送
请尝试收听
“android.net.conn.CONNECTIVITY\u CHANGE”
。可能重复:您是否已授予internet权限?是的,已授予权限。我尝试在代码上动态注册,它正在工作,但当活动完成时,它不再侦听。这意味着一般来说权限是好的哦,我想我弄错了,或者在某些地方写错了。我认为android.net.conn.CONNECTIVITY\u更改是一个被弃用的更改,因为我在自动完成中也找不到它。非常感谢,这很有效。