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