| Author |
how do i check for intenet connection in my app
|
Suzzane Pinto
Ranch Hand
Joined: Feb 10, 2012
Posts: 204
|
|
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
Ranch Hand
Joined: Jan 08, 2009
Posts: 1196
|
|
The android manifest is probably missing the following permission
android.permission.ACCESS_NETWORK_STATE
|
Swastik
|
 |
Suzzane Pinto
Ranch Hand
Joined: Feb 10, 2012
Posts: 204
|
|
|
i have given the permission still the same exception
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6592
|
|
|
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 - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
Suzzane Pinto
Ranch Hand
Joined: Feb 10, 2012
Posts: 204
|
|
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
Ranch Hand
Joined: Jan 08, 2009
Posts: 1196
|
|
|
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: 204
|
|
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: 204
|
|
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??
|
 |
 |
|
|
subject: how do i check for intenet connection in my app
|
|
|