aspose file tools*
The moose likes Android and the fly likes how do i check for intenet connection in my app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "how do i check for intenet connection in my app" Watch "how do i check for intenet connection in my app" New topic
Author

how do i check for intenet connection in my app

Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
hi,

i want to check for internet connection in my android app.and give the user a custom message if internet not available in phone....as i have connections to server everytym...
i have followed this link:
http://www.chrisdadswell.co.uk/android-coding-example-checking-for-the-presence-of-an-internet-connection-on-an-android-device/
but on implementation it gives me exception as:

please help if posible...
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1479
    
    6

The android manifest is probably missing the following permission

android.permission.ACCESS_NETWORK_STATE


Swastik
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
i have given the permission still the same exception
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Is the exception from the emulator ? If so, try wiping out user data for the emulator and restart it.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
hi;
i tried on both emulator and my device...now im not getting any exception niethr getting any output...with the same link....
any useful example or link if shared would be great

thankyou

Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1479
    
    6

The given seems to be returning just a true/false value. Are you doing something based on that return value?
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
hi,
i solved it using these lines

TextView tv = new TextView(this);
ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

if ( cm.getNetworkInfo(cm.TYPE_MOBILE).isConnectedOrConnecting() ||
cm.getNetworkInfo(cm.TYPE_WIFI).isConnectedOrConnecting() )
tv.setText("Network available!");
else
tv.setText("No network available!");
setContentView(tv);
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
hi...i have a problem..
when i tried integrating this in other project where i have given both internet and access_network_state permisssion...still it gives me exception as

why this exception coming when i have permissions??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do i check for intenet connection in my app