aspose file tools
The moose likes Android and the fly likes Are There a way to know if the internet(not network) disconnected Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Mobile » Android
Reply Bookmark "Are There a way to know if the internet(not network) disconnected" Watch "Are There a way to know if the internet(not network) disconnected" New topic
Author

Are There a way to know if the internet(not network) disconnected

Mohammed Al rifai
Greenhorn

Joined: Aug 27, 2010
Posts: 11
Dear
i want to know how i can detect the internet disconnected (by unplug the network cable from the router ) i solved network problem (shutdown router ) and i did it for internet by catching the exception but i am searching if there's better way like android.net.conn.CONNECTIVITY_CHANGE


Mohammed Al Rifai, Software Developer, SCJP 1.6, EJB 3.1
http://jo.linkedin.com/pub/mohammed-al-rifai/22/265/b66
Mohan Prasath
Ranch Hand

Joined: Jul 25, 2011
Posts: 38

You can use ConnectivityManager class for that. The implementation would look like
ConnectivityManager con = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return con.getActiveNetworkInfo().isConnectedOrConnecting();


Also you have to give the following permission in the AndroidManifest <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

I hope this is what you are looking for. If you want to look for connectivity changes while you are working in your application, you can always use a BroadcastReceiver to catch the network connectivity changes. I believe the following code would do that.

BroadcastReceiver receiver= new BroadcastReceiver() {

@Override
public void onReceive(Context context, Intent intent) {
Log.w("Network Connectivity Listener", "Network connections Changed");
}
};

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


With regards,
Mohan Prasath
Mohammed Al rifai
Greenhorn

Joined: Aug 27, 2010
Posts: 11
Dear Mohan
Thank you a lot for your time
I have used this already but this will detected network failure for example when router is shutdown but will not detect when the internet disconnected if the router working and you unplug the cable of the network
Mohan Prasath
Ranch Hand

Joined: Jul 25, 2011
Posts: 38

Yup. I have tested my code in your scenario. It still shows it is connected to network when there is no Internet Connection. . I'm working on this one.

For a work around, hit any websites using Http request, if you have network connection but no internet you will receive "CONNECTION_TIMED_OUT" exception. This might help you for now I Hope.
Mohammed Al rifai
Greenhorn

Joined: Aug 27, 2010
Posts: 11
thank you , i have implemented it using exception but was wonder if there is way similar(Broadcast) and i will keep search on and if i found solution i will keep you updated
Mohammed Al rifai
Greenhorn

Joined: Aug 27, 2010
Posts: 11
Thank you again
Mohan Prasath
Ranch Hand

Joined: Jul 25, 2011
Posts: 38

You are welcome . It's sad I can only give you work around. I will update you if I find any real solution.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Are There a way to know if the internet(not network) disconnected
 
Similar Threads
Hosting Tomcat from a subnetted network
How to find server name
How to Bypass router
Connection problems
RMI Server and Client behind two different routers