我已注册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).
}
}
}