views:

261

answers:

2

Hi all,

How i can know device is connected to Wifi or 3G, programmatically

Thanks

+3  A: 

you can use WifiManager class as mentioned here

Edit: by calling getConnectionInfo() function of WifiManager class you will get WifiInfo object

WifiInfo has function getBSSID() which gives you connected AP's name

if its null that means it is not connected to any AP via Wifi ( Wifi is not enabled )

btw while looking for more info, i found this which should answer all your questions about mobile connectivity and wifi connectivity

N30
The link shows about wifi connectivity is available or not. How i can know about 3G/2G is used to connect.Thank you,
Praveenb
I see this word in that link"if the device is connected via mobile"what is that means?that means via 3G/2G?Please let me knowThank you
Praveenb
not sure about how to find whether its connected to 3G/2G using sdk
N30
thank you for reply
Praveenb
thank you very much for reply
Praveenb
A: 

You have to check the network info e.g. like this

private boolean isOnline() {
        ConnectivityManager connectivityManager = (ConnectivityManager)
                    getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        boolean connected = networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected();
        return connected;
    }
Manfred Moser