Mel
Mel

Reputation: 6284

How to check for phone network on Android devices

I know how to check if I have internet access (using the code from this post),but is it possible to check if a phone has telephone network access? For example someone might have access to the internet via Wifi but not have phone network access to send SMS or make calls.

In my case, while using a real device (Samsung Galaxy S), I am able to turn of my 3G network (then the phone will detect I am not connected to the internet), but I am still able to make phone calls and send SMS. I guess I must be using some other network...

How do I test whether the phone network is connected? Do I need the TelephonyManager?

Thankyou for your time.

Mel

Upvotes: 2

Views: 5836

Answers (2)

angadsg
angadsg

Reputation: 184

The above answer did not work for one of my app users - he was connected to the Network but his NetworkType was unknown. Screenshot: http://dl.dropbox.com/u/5072192/SC20130317-161413.png

I am instead checking for the NetworkOperator field. (From the first answer here What is the correct way of checking for mobile network available (no data connection))

public static boolean isMobileAvailable(Context acontext) {       
    TelephonyManager tel = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);       
    return (tel.getNetworkOperator() != null && !tel.getNetworkOperator().equals(""));      
}

Upvotes: 2

Blundell
Blundell

Reputation: 76466

Sure would you not just use this: getNetworkType()

boolean hasNetwork = android.telephony.TelephonyManager.getNetworkType() != android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN; 
// True if the phone is connected to some type of network i.e. has signal

Upvotes: 3

Related Questions