您好我正在使用以下广播接收器代码来检查互联网连接
public class ConnectionChangeReceiver extends BroadcastReceiver{
@Override
public void onReceive( Context context, Intent intent )
{
Bundle bundle = intent.getExtras();
NetworkInfo activeNetInfo = (NetworkInfo) bundle.getParcelable("networkInfo");
//On Network Re-Availability Display The Screen
if (activeNetInfo != null && activeNetInfo.isConnectedOrConnecting())
{
//If URL is not loaded load default URL else Resume
if (mWebView.getUrl()==null){
mWebView.loadUrl( Main.this.getString( R.string.app_url));
}
} //Else Show error message
else
{
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle(Main.this.getString(R.string.Internet_connectivity_failure_message_title));
alertDialog.setMessage(Main.this.getString(R.string.Internet_connectivity_failure_message));
alertDialog.setButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {}
});
alertDialog.show();
}
}
}
启用WIFI或移动网络时,它可以正常工作。但是,当两者都启用时,它会按预期使用WIFI,但方法activeNetInfo.isConnectedOrConnecting()
结果在True
和False
之间波动,因此无法连接到互联网。
是什么导致这个问题?
感谢。