• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how do i check for intenet connection in my app

 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The android manifest is probably missing the following permission

android.permission.ACCESS_NETWORK_STATE
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have given the permission still the same exception
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the exception from the emulator ? If so, try wiping out user data for the emulator and restart it.
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The given seems to be returning just a true/false value. Are you doing something based on that return value?
 
Suzzane Pinto
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic