Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6995655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:03:27+00:00 2026-05-27T20:03:27+00:00

I am currently developing Web Crawling in android I have a code to check

  • 0

I am currently developing Web Crawling in android

I have a code to check whether there is internet connection or not

but if i turned the mobile network the application suddenly error wanted to force close
here are some code :

package thesis.carlo;

@Override
protected void onHandleIntent(Intent intent) {
    // TODO Auto-generated method stub

    receiver = new ConnectivityReceiver();
    registerReceiver(receiver, new IntentFilter(
            ConnectivityManager.CONNECTIVITY_ACTION));



    Notification note = new Notification(R.drawable.target, "Crawling", System.currentTimeMillis());
    Intent i = new Intent(this, LoadingActivity.class);

    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);

    note.setLatestEventInfo(this, "Focused Crawling","In Progress Crawling...", pi);
    note.flags |= Notification.FLAG_NO_CLEAR;

    startForeground(1337, note);


    this.crawls(resultMap, keywords);

    stopForeground (true);

    this.showResult(urlsList, valueList);
    result = Activity.RESULT_OK;


}


public void showResult(List urlList, List valList) {

    Intent i = new Intent(this, ResultActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.putStringArrayListExtra("urlsList", (ArrayList<String>) urlList);
    i.putParcelableArrayListExtra("valueList",
            (ArrayList<? extends Parcelable>) valList);
    startActivity(i);
}

private String getNetworkStateString(NetworkInfo.State state) {
    String stateString = "Unknown";

    switch (state) {
    case CONNECTED:
        stateString = "Connected";
        break;
    case CONNECTING:
        stateString = "Connecting";
        break;
    case DISCONNECTED:
        stateString = "Disconnected";
        break;
    case DISCONNECTING:
        stateString = "Disconnecting";
        break;
    case SUSPENDED:
        stateString = "Suspended";
        break;
    default:
        stateString = "Unknown";
        break;
    }

    return stateString;
}

public void onDestroy() {
    unregisterReceiver(receiver);

    super.onDestroy();
}

private class ConnectivityReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        NetworkInfo info = intent
                .getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);

        if (null != info) {
            String state = getNetworkStateString(info.getState());
            String stateString = info.toString().replace(',', '\n');

            Log.i("ConnTest", info.getTypeName());
            Log.i("ConnTest", state);
            Log.i("ConnTest", info.toString());

            if(state.equals("Disconnected")){
                stop();
            }

        }
    }
}

public void stop(){
    stopService(new Intent(this, CrawlingActivityService.class));
    startActivity(new Intent(this, ErrorActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    stopForeground (true);
}

}

I dont know why the onReceive method didn’t invoke when I turned of the mobile network

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:03:27+00:00Added an answer on May 27, 2026 at 8:03 pm

    To check whether Internet is there or not you can use the following code:

    public static Boolean isOnline(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnectedOrConnecting()) {
            return true;
        }
        return false;
    }
    

    This code returns true if Internet is present and false if it is not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently developing a web app targeting primarily iOS devices (but possibly Android
I'm developing a web app and currently using sql server 2008 for it. But,
I am developing a web form using Visual Web Developer Currently I have class
I'm currently developing a web application and have run into a little problem. I'm
In the web app I am currently developing I have a form, and one
I am currently developing a Web Site (not a Web Application) in VS2008. I
I have a problem with an Api I'm currently developing with WCF Web Api,
In the web application I am currently developing, I have quite a few database
I am currently developing a web site using ASP.NET 3.5. On a page there
I am currently developing an Android application which has a web backend. I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.