Checking Internet Connectivity

Put your problem here if it does not fit any of the other categories.

Checking Internet Connectivity

Postby drake » Sun Mar 30, 2008 1:15 pm

I thought this would be easy to find, but I just could not figure out how to check whether the phone/emulator is connected to the internet.

We are trying to post something to a server, and we need to detect whether there is an internet connection. Is there a way to do this on android?

Thanks in advanced.
drake
Freshman
Freshman
 
Posts: 4
Joined: Thu Feb 28, 2008 1:45 am

Top

Postby plusminus » Sun Mar 30, 2008 4:53 pm

Hello drake,

have a look at the DataStateIntentReceiver.

I'll make a TinyTut of this, wait some seconds and check the Novice-Tutorials.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby plusminus » Sun Mar 30, 2008 5:13 pm

Hello drake,

There it is:
:arrow: http://www.anddev.org/viewtopic.php?t=1548

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

getting "CONNECTED" every time.

Postby drake » Mon Mar 31, 2008 1:05 am

Hey plusminus. Thanks so much for your prompt reply. I really appreciate all the help. However, I am still having problems implementing the datastateintentreceiver.

1) In my switch statement, I ALWAYS get a "CONNECTED" data state, even after I turn my internet off.

2) There doesn't seem to be any information on the class DataState. How did you know to use it?

Here is a snippet of my code:

GLOBAL VARIABLES:
private static final int GETCONNECTION = 1;
protected DataStateIntentReceiver dsir;

IN ONCREATE():

dsir = new DataStateIntentReceiver(this, connection_handler);
dsir.notifyConnectionState(GETCONNECTION);
dsir.registerIntent();

SEPARATE HANDLER CREATED IN THE SAME ACTIVITY CLASS:

private Handler connection_handler = new Handler(){
@Override
public void handleMessage(Message msg) {

DataState ds = dsir.getConnectionState();
Log.i(TAG,"This is the value of connected = "+ds.toString());

/* check connection state */
switch(ds){
case CONNECTED:
Log.i(TAG, "I'M CONNECTED!");
break;
case CONNECTING:
break;
case DISCONNECTED:
Log.i(TAG, "I'M DISCONNECTED!!!");
break;
}
super.handleMessage(msg);
}
};

Again, thanks in advanced.
drake
Freshman
Freshman
 
Posts: 4
Joined: Thu Feb 28, 2008 1:45 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 25 guests