how to check whether network is connected or not in android mobile phone..(network means not internet connection,, its simple mobile network like IDEA,AIRTEL etc..) please help me
Asked
Active
Viewed 455 times
4 Answers
0
Ok so you just want to check the network connections? This method seems to be pretty good for it! http://smartandroidians.blogspot.co.uk/2010/03/checking-network-connection-in-android.html Give that a go and hopefully that'll sort it :)

Craig
- 556
- 1
- 8
- 23
-
In the link what is connection manager.. didnt get that, pls help me out,, thanks for ur help – diordna Aug 16 '12 at 10:05
-
It is basically Android's function to check what/who is connected to where :) http://developer.android.com/reference/org/apache/http/conn/ClientConnectionManager.html Thats the dev link for it :) – Craig Aug 16 '12 at 10:13
0
You can retrieve both SIM and network Operator using TelephonyManager
as:
TelephonyManager telephonyManager =((TelephonyManager)
Context.getSystemService(Context.TELEPHONY_SERVICE));
// Network operator IDEA,AIRTEL...
String networkOperatorName = telephonyManager.getNetworkOperatorName();
// sim operator IDEA,AIRTEL,BSNL,MTNL...
String simOperatorName = telephonyManager.getSimOperatorName();

ρяσѕρєя K
- 132,198
- 53
- 198
- 213
-
i don't want operator name.. i just want whether network is there or not.. thank u – diordna Aug 16 '12 at 10:09
-
@diordna : i got you i think you will need to find out all available Networks Providers Name ? then plz check-out http://stackoverflow.com/questions/3123697/how-to-get-a-list-of-available-network-providers – ρяσѕρєя K Aug 16 '12 at 10:17
0
/**
* Checking whether net connection is available or not.
*
* @param nContext
* @return true if net connection is avaible otherwise false
*/
public static boolean isNetworkAvailable(Context nContext) {
boolean isNetAvailable = false;
if (nContext != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) nContext
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (mConnectivityManager != null) {
boolean mobileNetwork = false;
boolean wifiNetwork = false;
boolean mobileNetworkConnecetd = false;
boolean wifiNetworkConnecetd = false;
NetworkInfo mobileInfo = mConnectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo wifiInfo = mConnectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mobileInfo != null)
mobileNetwork = mobileInfo.isAvailable();
if (wifiInfo != null)
wifiNetwork = wifiInfo.isAvailable();
if (wifiNetwork == true || mobileNetwork == true) {
if (mobileInfo != null)
mobileNetworkConnecetd = mobileInfo
.isConnectedOrConnecting();
wifiNetworkConnecetd = wifiInfo.isConnectedOrConnecting();
}
isNetAvailable = (mobileNetworkConnecetd || wifiNetworkConnecetd);
}
}
return isNetAvailable;
}
Also add below tag in manifest permission:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Utsav
- 1
- 2