1

Hello I am using following broadcast receiver code to check internet connectivity

 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();                 
        }               
    }
} 

It works fine when either WIFI or Mobile Network is enabled. However when both are enabled, it uses WIFI as expected, but the method activeNetInfo.isConnectedOrConnecting() result fluctuates between True and False , hence not connecting to the internet. What is causing this problem any idea?

Thanks.

Tushar Vengurlekar
  • 7,649
  • 8
  • 33
  • 48
  • see this link [broadcast receiver] http://stackoverflow.com/questions/10545822/how-to-make-call-to-service-from-receiver-depends-on-internet-connected-or-not/10546152#10546152 – Vicky Oct 15 '12 at 09:25

0 Answers0