在Marshmallow中启用移动数据时,连接已更改广播不起作用

时间:2016-07-08 16:20:25

标签: android broadcastreceiver data-connections

我已注册ConnectivityManager.CONNECTIVITY_ACTION以便在WIFI is connected时播放。当mobile data is enabled和已连接的WIFI没有互联网连接时,它无效。

我在另一台没有互联网连接的移动设备上创建了hotspot。在my device (Android 6.1) mobile data已启用。当我尝试连接到hotspot时,广播不会触发。它每次mobile data is disable时都有效。

IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(networkStateReceiver, intentFilter);

private BroadcastReceiver networkStateReceiver = new BroadcastReceiver()
{
        public void onReceive(Context context, Intent intentData)
        {
            String action = intentData.getAction();
            Log.e("action",action);
            if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)){
                // trigger once (when register).
            }
        }
}

0 个答案:

没有答案