Java Code Examples for android.net.ConnectivityManager
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.
Source file: DataFetcher.java

public boolean isOnline(Context context){ ConnectivityManager cm=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info=cm.getActiveNetworkInfo(); if (info == null) { return false; } else { return info.isConnectedOrConnecting(); } }
Example 2
From project HabReader, under directory /src/net/meiolania/apps/habrahabr/utils/.
Source file: ConnectionUtils.java

public static boolean isConnected(Context context){ ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (manager.getActiveNetworkInfo() != null) { if (manager.getActiveNetworkInfo().isAvailable() && manager.getActiveNetworkInfo().isConnected()) return true; else return false; } else return false; }
Example 3
From project ignition, under directory /ignition-location/ignition-location-lib/src/com/github/ignition/location/receivers/.
Source file: IgnitedConnectivityChangedReceiver.java

@Override public void onReceive(Context context,Intent intent){ ConnectivityManager cm=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork=cm.getActiveNetworkInfo(); boolean isConnected=(activeNetwork != null) && activeNetwork.isConnectedOrConnecting(); if (isConnected) { PackageManager pm=context.getPackageManager(); ComponentName connectivityReceiver=new ComponentName(context,IgnitedConnectivityChangedReceiver.class); ComponentName locationReceiver=new ComponentName(context,IgnitedLocationChangedReceiver.class); ComponentName passiveLocationReceiver=new ComponentName(context,IgnitedPassiveLocationChangedReceiver.class); pm.setComponentEnabledSetting(connectivityReceiver,PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(locationReceiver,PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(passiveLocationReceiver,PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,PackageManager.DONT_KILL_APP); } }
Example 4
From project iosched_3, under directory /android/src/com/google/android/apps/iosched/ui/.
Source file: AccountActivity.java

@Override public void onListItemClick(ListView l,View v,int position,long id){ AccountActivity activity=(AccountActivity)getActivity(); ConnectivityManager cm=(ConnectivityManager)activity.getSystemService(CONNECTIVITY_SERVICE); NetworkInfo activeNetwork=cm.getActiveNetworkInfo(); if (activeNetwork == null || !activeNetwork.isConnected()) { Toast.makeText(activity,R.string.no_connection_cant_login,Toast.LENGTH_SHORT).show(); return; } activity.mCancelAuth=false; activity.mChosenAccount=mAccountListAdapter.getItem(position); activity.getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new AuthProgressFragment(),"loading").addToBackStack("choose_account").commit(); activity.tryAuthenticate(); }
Example 5
From project Juggernaut_SystemUI, under directory /src/com/android/systemui/statusbar/powerwidget/.
Source file: MobileDataButton.java

@Override protected void toggleState(){ Context context=mView.getContext(); boolean enabled=getDataState(context); ConnectivityManager cm=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (enabled) { cm.setMobileDataEnabled(false); } else { cm.setMobileDataEnabled(true); } }
Example 6
/** * Check to see if we have network connectivity. * @param app Current application (Hint: see if your base class has a getApplication() method.) * @return true if we have connectivity, false otherwise. */ public static boolean hasConnectivity(final Application app){ final ConnectivityManager connectivityManager=(ConnectivityManager)app.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { return false; } final NetworkInfo netInfo=connectivityManager.getActiveNetworkInfo(); if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) { return true; } else { return false; } }
Example 7
From project android_7, under directory /src/org/immopoly/android/helper/.
Source file: Settings.java

public static boolean isOnline(Context context){ ConnectivityManager cm=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() == null) { return false; } return cm.getActiveNetworkInfo().isConnectedOrConnecting(); }
Example 8
From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/deviceinfo/.
Source file: Status.java

private void setWimaxStatus(){ ConnectivityManager cm=(ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE); NetworkInfo ni=cm.getNetworkInfo(ConnectivityManager.TYPE_WIMAX); if (ni == null) { PreferenceScreen root=getPreferenceScreen(); Preference ps=(Preference)findPreference(KEY_WIMAX_MAC_ADDRESS); if (ps != null) root.removePreference(ps); } else { Preference wimaxMacAddressPref=findPreference(KEY_WIMAX_MAC_ADDRESS); String macAddress=SystemProperties.get("net.wimax.mac.address",getString(R.string.status_unavailable)); wimaxMacAddressPref.setSummary(macAddress); } }
Example 9
From project android_packages_apps_phone, under directory /src/com/android/phone/.
Source file: Settings.java

@Override protected void onResume(){ super.onResume(); getPreferenceScreen().setEnabled(true); ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); mButtonDataEnabled.setChecked(cm.getMobileDataEnabled()); mButtonDataRoam.setChecked(mPhone.getDataRoamingEnabled()); if (getPreferenceScreen().findPreference(BUTTON_PREFERED_NETWORK_MODE) != null) { mPhone.getPreferredNetworkType(mHandler.obtainMessage(MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE)); } mDataUsageListener.resume(); }
Example 10
From project groundy, under directory /src/main/java/com/codeslap/groundy/.
Source file: DeviceStatus.java

/** * Checks whether there's a network connection * @param context Context to use * @return true if there's an active network connection, false otherwise */ public static boolean isOnline(Context context){ ConnectivityManager cm=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm == null) { return false; } NetworkInfo info=cm.getActiveNetworkInfo(); return info != null && info.isConnectedOrConnecting(); }
Example 11
From project Absolute-Android-RSS, under directory /src/com/AA/Other/.
Source file: RSSParse.java

/** * Check if the network is available for get the RSS feed * @param isBackground if the request is being run in the background * @param callingContext current application context * @return if the network is in a state where a request can be sent */ private static boolean isNetworkAvailable(boolean isBackground,Context callingContext){ ConnectivityManager manager=(ConnectivityManager)callingContext.getSystemService(Context.CONNECTIVITY_SERVICE); if (isBackground && !manager.getBackgroundDataSetting()) return false; NetworkInfo netInfo=manager.getActiveNetworkInfo(); if (netInfo == null || manager.getActiveNetworkInfo().getState() != NetworkInfo.State.CONNECTED) return false; return true; }
Example 12
From project Airports, under directory /src/com/nadmm/airports/utils/.
Source file: NetworkUtils.java

public static boolean isNetworkAvailable(Context context){ ConnectivityManager connMan=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo network=connMan.getActiveNetworkInfo(); if (network == null || !network.isConnected()) { UiUtils.showToast(context,"Please check your internet connection"); return false; } return true; }
Example 13
From project aksunai, under directory /src/org/androidnerds/app/aksunai/.
Source file: Aksunai.java

public void connectToServer(long id,String name){ ConnectivityManager manager=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info=manager.getActiveNetworkInfo(); if (info == null || !info.isConnected()) { Toast.makeText(Aksunai.this,getString(R.string.no_network_connection),Toast.LENGTH_LONG).show(); return; } Intent i=new Intent(Aksunai.this,ChatActivity.class); i.putExtra("id",id); i.putExtra("title",name); startActivity(i); }
Example 14
From project android-bankdroid, under directory /src/com/liato/bankdroid/appwidget/.
Source file: AutoRefreshService.java

private void handleStart(Intent intent,int startId){ ConnectivityManager cm=(ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting()) { if (InsideUpdatePeriod()) { new DataRetrieverTask().execute(); } else { Log.v(TAG,"Skipping update due to not in update period."); stopSelf(); } } }
Example 15
From project android-flash-cards, under directory /src/org/thomasamsler/android/flashcards/activity/.
Source file: MainActivity.java

public boolean hasConnectivity(){ ConnectivityManager connectivityManager=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); if (null == connectivityManager) { return false; } NetworkInfo networkInfo=connectivityManager.getActiveNetworkInfo(); if (null != networkInfo && networkInfo.isAvailable() && networkInfo.isConnected()) { return true; } else { return false; } }
Example 16
From project Android-RTMP, under directory /android-ffmpeg-prototype/src/com/camundo/util/.
Source file: NetworkUtils.java

public static boolean isOnline(Context context){ ConnectivityManager cm=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo=cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnected()) { return true; } return false; }
Example 17
From project AndroidCommon, under directory /src/com/asksven/android/common/networkutils/.
Source file: DataNetwork.java

public static boolean hasDataConnection(Context ctx){ boolean ret=true; ConnectivityManager myConnectivity=(ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE); if ((myConnectivity == null) || (myConnectivity.getActiveNetworkInfo() == null) || (!myConnectivity.getActiveNetworkInfo().isAvailable())) { ret=false; } return ret; }
Example 18
From project android_packages_apps_QuickSearchBox, under directory /src/com/android/quicksearchbox/google/.
Source file: GoogleSuggestClient.java

private NetworkInfo getActiveNetworkInfo(){ ConnectivityManager connectivity=(ConnectivityManager)getContext().getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { return null; } return connectivity.getActiveNetworkInfo(); }
Example 19
/** * We use this function before actual requests of Internet services Based on http ://stackoverflow.com/questions/1560788/how-to-check-internet-access-on -android-inetaddress-never-timeouts */ public boolean isOnline(){ ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isAvailable() && cm.getActiveNetworkInfo().isConnected()) { return true; } else { MyLog.v(TAG,"Internet Connection Not Present"); return false; } }
Example 20
From project andtweet, under directory /src/com/xorcode/andtweet/.
Source file: AndTweetService.java

/** * We use this function before actual requests of Internet services Based on http ://stackoverflow.com/questions/1560788/how-to-check-internet-access-on -android-inetaddress-never-timeouts */ public boolean isOnline(){ ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isAvailable() && cm.getActiveNetworkInfo().isConnected()) { return true; } else { v(TAG,"Internet Connection Not Present"); return false; } }
Example 21
public static boolean isOnline(){ ConnectivityManager cm=(ConnectivityManager)sContext.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() != null) { return cm.getActiveNetworkInfo().isConnectedOrConnecting(); } else { return false; } }
Example 22
From project BBC-News-Reader, under directory /src/com/digitallizard/bbcnewsreader/.
Source file: ResourceService.java

boolean isOnline(){ ConnectivityManager manager=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info=manager.getActiveNetworkInfo(); if (info != null) { return info.isConnected(); } else { return false; } }
Example 23
From project beintoo-android-sdk, under directory /BeintooSDK/src/com/beintoo/beintoosdk/.
Source file: BeintooConnection.java

/** * Check if is active the internet connection - REMOVED * @param ctx current application Context * @return a boolean that return the connection state */ public static boolean isOnline(Context ctx){ ConnectivityManager connectivity=(ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info=connectivity.getAllNetworkInfo(); if (info != null) { for (int i=0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } } } return false; }
Example 24
From project BF3-Battlelog, under directory /src/com/ninetwozero/battlelog/misc/.
Source file: PublicUtils.java

public static boolean isNetworkAvailable(final Context c){ ConnectivityManager connMan=(ConnectivityManager)c.getSystemService(Context.CONNECTIVITY_SERVICE); if (connMan.getActiveNetworkInfo() != null) { NetworkInfo networkInfo=connMan.getActiveNetworkInfo(); if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE && connMan.getBackgroundDataSetting()) { return true; } } return false; }
Example 25
From project bitfluids, under directory /src/main/java/at/bitcoin_austria/bitfluids/trafficSignal/.
Source file: TrafficSignal.java

private void checkInternet(TrafficSignalReciever trafficSignalReciever){ ConnectivityManager connectivityManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo=connectivityManager.getActiveNetworkInfo(); Status status=activeNetworkInfo == null ? Status.RED : Status.GREEN; trafficSignalReciever.onStatusChanged(SignalType.NETWORK,status); }
Example 26
From project BombusLime, under directory /src/org/bombusim/lime/service/.
Source file: XmppService.java

public void checkNetworkState(){ try { ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); networkAvailable=cm.getActiveNetworkInfo().isAvailable(); int networkType=cm.getActiveNetworkInfo().getType(); this.networkType=networkType; Lime.getInstance().vcardResolver.setOnMobile(networkType == ConnectivityManager.TYPE_MOBILE); } catch ( Exception e) { networkAvailable=false; } }
Example 27
From project Book-Catalogue, under directory /src/com/eleybourn/bookcatalogue/.
Source file: Utils.java

public static boolean isNetworkAvailable(Context context){ ConnectivityManager connectivity=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info=connectivity.getAllNetworkInfo(); if (info != null) { for (int i=0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } } } return false; }
Example 28
From project Cafe, under directory /testservice/src/com/baidu/cafe/remote/.
Source file: SystemLib.java

/** * set background data * @param enabled */ public void setBackgroundDataSetting(boolean enabled){ ConnectivityManager cm=(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); cm.setBackgroundDataSetting(enabled); try { Thread.sleep(1000); } catch ( InterruptedException e) { e.printStackTrace(); } }
Example 29
private boolean wifiNetworkActive(){ ConnectivityManager con=(ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE); if (con != null) { NetworkInfo netInfo=con.getActiveNetworkInfo(); if (netInfo == null) { return false; } if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; } } return false; }
Example 30
From project connectbot, under directory /src/sk/vx/connectbot/service/.
Source file: ConnectivityReceiver.java

public ConnectivityReceiver(TerminalManager manager,boolean lockingWifi){ mTerminalManager=manager; final ConnectivityManager cm=(ConnectivityManager)manager.getSystemService(Context.CONNECTIVITY_SERVICE); final WifiManager wm=(WifiManager)manager.getSystemService(Context.WIFI_SERVICE); mWifiLock=wm.createWifiLock(TAG); final NetworkInfo info=cm.getActiveNetworkInfo(); if (info != null) { mIsConnected=(info.getState() == State.CONNECTED); } mLockingWifi=lockingWifi; final IntentFilter filter=new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); manager.registerReceiver(this,filter); }
Example 31
From project creamed_glacier_app_settings, under directory /src/com/android/settings/.
Source file: DataUsageSummary.java

/** * Test if device has a mobile data radio. */ private static boolean hasMobileRadio(Context context){ if (TEST_RADIOS) { return SystemProperties.get(TEST_RADIOS_PROP).contains("mobile"); } final ConnectivityManager conn=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); return conn.isNetworkSupported(TYPE_MOBILE); }
Example 32
public static boolean checkInternetConnection(Context context){ ConnectivityManager connectivityManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isAvailable() && connectivityManager.getActiveNetworkInfo().isConnected()) { return true; } else { return false; } }
Example 33
From project fanfoudroid, under directory /src/com/ch_linghu/fanfoudroid/.
Source file: TwitterApplication.java

public String getNetworkType(){ ConnectivityManager connectivityManager=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo=connectivityManager.getActiveNetworkInfo(); if (activeNetInfo != null) { return activeNetInfo.getExtraInfo(); } else { return null; } }
Example 34
From project GeekAlarm, under directory /android/src/com/geek_alarm/android/.
Source file: Utils.java

/** * Checks if device is connected to internet. * @return true or false. */ public static boolean isOnline(){ Context context=Application.getContext(); ConnectivityManager cm=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo=cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { return true; } return false; }
Example 35
From project generic-store-for-android, under directory /src/com/wareninja/opensource/common/.
Source file: WareNinjaUtils.java

public static boolean checkInternetConnection(Context context){ ConnectivityManager conMgr=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected()) { return true; } else { Log.w(TAG,"Internet Connection NOT Present"); return false; } }
Example 36
From project gh4a, under directory /src/com/gh4a/.
Source file: BaseSherlockFragmentActivity.java

public boolean isOnline(){ ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isAvailable() && cm.getActiveNetworkInfo().isConnected()) { return true; } else { return false; } }
Example 37
From project Gibberbot, under directory /src/info/guardianproject/otr/app/im/service/.
Source file: RemoteImService.java

@Override public void onReceive(Context context,Intent intent){ String action=intent.getAction(); if (ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED.equals(action)) { ConnectivityManager manager=(ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE); setBackgroundData(manager.getBackgroundDataSetting()); handleBackgroundDataSettingChange(); } }
Example 38
From project milton, under directory /milton/apps/milton-android-photouploader/src/com/ettrema/android/photouploader/.
Source file: CheckInternet.java

/** * Can we connect to the internet or not, checks if device has connection and if wifi is on if user has set that in the connection preference * @param context Application context * @param prefs User preferences * @return Can connect to internet or not */ @SuppressWarnings("static-access") public boolean canConnect(Context context,SharedPreferences prefs){ WifiManager wifi=(WifiManager)context.getSystemService(Context.WIFI_SERVICE); if (wifi.getWifiState() != wifi.WIFI_STATE_ENABLED && prefs.getString("connection","").equals(CON_WIFI)) { return false; } ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (manager.getActiveNetworkInfo() == null || !manager.getActiveNetworkInfo().isConnected()) { return false; } return true; }
Example 39
From project milton2, under directory /apps/milton-android-photouploader/src/com/ettrema/android/photouploader/.
Source file: CheckInternet.java

/** * Can we connect to the internet or not, checks if device has connection and if wifi is on if user has set that in the connection preference * @param context Application context * @param prefs User preferences * @return Can connect to internet or not */ @SuppressWarnings("static-access") public boolean canConnect(Context context,SharedPreferences prefs){ WifiManager wifi=(WifiManager)context.getSystemService(Context.WIFI_SERVICE); if (wifi.getWifiState() != wifi.WIFI_STATE_ENABLED && prefs.getString("connection","").equals(CON_WIFI)) { return false; } ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (manager.getActiveNetworkInfo() == null || !manager.getActiveNetworkInfo().isConnected()) { return false; } return true; }
Example 40
From project Novocation, under directory /core/src/main/java/com/novoda/location/receiver/.
Source file: UnregisterPassiveListenerOnLostConnectivity.java

private boolean isNotConnected(Context context){ ConnectivityManager cm=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork=cm.getActiveNetworkInfo(); if (activeNetwork == null) { return true; } if (activeNetwork.isConnectedOrConnecting()) { return false; } return true; }
Example 41
From project official-android-app--DEPRECATED-, under directory /src/com/plancake/android/app/.
Source file: Utils.java

public static boolean isNetworkAvailable(Context activity){ ConnectivityManager connectivityManager=(ConnectivityManager)activity.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo=connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { return networkInfo.isAvailable(); } return false; }
Example 42
From project OpenAndroidWeather, under directory /OpenAndroidWeather/src/no/firestorm/misc/.
Source file: CheckInternetStatus.java

/** * Return true is connected to internet * @param context * @return true is connected to internet */ public static boolean isConnected(Context context){ final ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo info=manager.getActiveNetworkInfo(); if (info != null) return info.isConnected(); else return false; }
Example 43
From project packages_apps_Phone_1, under directory /src/com/android/phone/.
Source file: PhoneInterfaceManager.java

public boolean enableDataConnectivity(){ enforceModifyPermission(); ConnectivityManager cm=(ConnectivityManager)mApp.getSystemService(Context.CONNECTIVITY_SERVICE); cm.setMobileDataEnabled(true); return true; }
Example 44
From project platform_packages_apps_browser, under directory /src/com/android/browser/search/.
Source file: OpenSearchSearchEngine.java

private NetworkInfo getActiveNetworkInfo(Context context){ ConnectivityManager connectivity=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { return null; } return connectivity.getActiveNetworkInfo(); }
Example 45
From project platform_packages_apps_CytownPhone, under directory /src/com/android/phone/.
Source file: Settings.java

@Override protected void onResume(){ super.onResume(); getPreferenceScreen().setEnabled(true); ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); mButtonDataEnabled.setChecked(cm.getMobileDataEnabled()); mButtonDataRoam.setChecked(mPhone.getDataRoamingEnabled()); if (getPreferenceScreen().findPreference(BUTTON_PREFERED_NETWORK_MODE) != null) { mPhone.getPreferredNetworkType(mHandler.obtainMessage(MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE)); } mDataUsageListener.resume(); }
Example 46
From project platform_packages_apps_im, under directory /src/com/android/im/service/.
Source file: RemoteImService.java

@Override public void onReceive(Context context,Intent intent){ String action=intent.getAction(); if (ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED.equals(action)) { ConnectivityManager manager=(ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE); setBackgroundData(manager.getBackgroundDataSetting()); handleBackgroundDataSettingChange(); } }
Example 47
From project platform_packages_apps_phone, under directory /src/com/android/phone/.
Source file: MobileNetworkSettings.java

@Override protected void onResume(){ super.onResume(); getPreferenceScreen().setEnabled(true); ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); mButtonDataEnabled.setChecked(cm.getMobileDataEnabled()); mButtonDataRoam.setChecked(mPhone.getDataRoamingEnabled()); if (getPreferenceScreen().findPreference(BUTTON_PREFERED_NETWORK_MODE) != null) { mPhone.getPreferredNetworkType(mHandler.obtainMessage(MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE)); } mDataUsageListener.resume(); }
Example 48
From project platform_packages_apps_settings, under directory /src/com/android/settings/.
Source file: DataUsageSummary.java

/** * Test if device has a mobile data radio with SIM in ready state. */ public static boolean hasReadyMobileRadio(Context context){ if (TEST_RADIOS) { return SystemProperties.get(TEST_RADIOS_PROP).contains("mobile"); } final ConnectivityManager conn=ConnectivityManager.from(context); final TelephonyManager tele=TelephonyManager.from(context); return conn.isNetworkSupported(TYPE_MOBILE) && tele.getSimState() == SIM_STATE_READY; }
Example 49
From project android-sdk, under directory /src/main/java/com/mobeelizer/mobile/android/.
Source file: MobeelizerRealConnectionManager.java

@Override public boolean isNetworkAvailable(){ ConnectivityManager connectivityManager=(ConnectivityManager)application.getContext().getSystemService(Context.CONNECTIVITY_SERVICE); if (isConnected(connectivityManager)) { return true; } for (int i=0; i < 10; i++) { if (isConnecting(connectivityManager)) { try { Thread.sleep(500); } catch ( InterruptedException e) { Log.w(TAG,e.getMessage(),e); break; } if (isConnected(connectivityManager)) { return true; } } } return false; }
Example 50
From project androidpn, under directory /androidpn-client/src/org/androidpn/client/.
Source file: ConnectivityReceiver.java

@Override public void onReceive(Context context,Intent intent){ Log.d(LOGTAG,"ConnectivityReceiver.onReceive()..."); String action=intent.getAction(); Log.d(LOGTAG,"action=" + action); ConnectivityManager connectivityManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo=connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { Log.d(LOGTAG,"Network Type = " + networkInfo.getTypeName()); Log.d(LOGTAG,"Network State = " + networkInfo.getState()); if (networkInfo.isConnected()) { Log.i(LOGTAG,"Network connected"); notificationService.connect(); } } else { Log.e(LOGTAG,"Network unavailable"); notificationService.disconnect(); } }
Example 51
From project android_packages_apps_Exchange, under directory /src/com/android/exchange/.
Source file: AbstractSyncService.java

/** * Waits for up to 10 seconds for network connectivity; returns whether or not there is network connectivity. * @return whether there is network connectivity */ public boolean hasConnectivity(){ ConnectivityManager cm=(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); int tries=0; while (tries++ < 1) { NetworkInfo info=cm.getActiveNetworkInfo(); if (info != null) { return true; } try { Thread.sleep(10 * SECONDS); } catch ( InterruptedException e) { } } return false; }
Example 52
From project anode, under directory /src/net/haltcondition/anode/.
Source file: WidgetUpdater.java

private void initiateUsageUpdate(Context context){ this.ctx=context; SettingsHelper settings=new SettingsHelper(context); ConnectivityManager cmgr=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (!cmgr.getBackgroundDataSetting() || (settings.getWifiOnly() && cmgr.getActiveNetworkInfo().getType() != ConnectivityManager.TYPE_WIFI)) { Log.i(TAG,"Skipping as background sync disabled or WiFi not enabled"); return; } Account account=settings.getAccount(); Service service=settings.getService(); if (account == null || service == null) { Log.w(TAG,"Account or Service not available, doing nothing"); return; } HttpWorker<Usage> usageWorker=new HttpWorker<Usage>(new Handler(this),account,Common.usageUri(service),new UsageParser(),context); pool.execute(usageWorker); }
Example 53
From project DigitbooksExamples, under directory /DigitbooksExamples/src/fr/digitbooks/android/examples/util/.
Source file: Helpers.java

/** * Retourne la disponibilit d'une connection r?eau */ public static boolean isNetworkAvailable(Context context){ ConnectivityManager connectivity=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { Log.w(LOG_TAG,"erreur, service indisponible"); } else { NetworkInfo[] info=connectivity.getAllNetworkInfo(); if (info != null) { for (int i=0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { if (Config.INFO_LOGS_ENABLED) { Log.i(LOG_TAG,"Network is available"); } return true; } } } } if (Config.INFO_LOGS_ENABLED) { Log.i(LOG_TAG,"Network is not available"); } return false; }
Example 54
From project DownloadProvider, under directory /src/com/mozillaonline/providers/downloads/.
Source file: RealSystemFacade.java

public Integer getActiveNetworkType(){ ConnectivityManager connectivity=(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { Log.w(Constants.TAG,"couldn't get connectivity manager"); return null; } NetworkInfo activeInfo=connectivity.getActiveNetworkInfo(); if (activeInfo == null) { if (Constants.LOGVV) { Log.v(Constants.TAG,"network is not available"); } return null; } return activeInfo.getType(); }
Example 55
From project droid-fu, under directory /src/main/java/com/github/droidfu/http/.
Source file: BetterHttp.java

public static void updateProxySettings(){ if (appContext == null) { return; } HttpParams httpParams=httpClient.getParams(); ConnectivityManager connectivity=(ConnectivityManager)appContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo=connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return; } Log.i(LOG_TAG,nwInfo.toString()); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost=Proxy.getHost(appContext); if (proxyHost == null) { proxyHost=Proxy.getDefaultHost(); } int proxyPort=Proxy.getPort(appContext); if (proxyPort == -1) { proxyPort=Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy=new HttpHost(proxyHost,proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY,null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY,null); } }
Example 56
From project FileExplorer, under directory /src/net/micode/fileexplorer/.
Source file: FTPServerService.java

public static boolean isWifiEnabled(){ Context myContext=Globals.getContext(); if (myContext == null) { throw new NullPointerException("Global context is null"); } WifiManager wifiMgr=(WifiManager)myContext.getSystemService(Context.WIFI_SERVICE); if (wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) { ConnectivityManager connManager=(ConnectivityManager)myContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiInfo=connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); return wifiInfo.isConnected(); } else { return false; } }
Example 57
From project FlipDroid, under directory /app/src/com/goal98/flipdroid2/util/.
Source file: NetworkUtil.java

public static boolean isNetworkAvailable(Context context){ if (context != null) { ConnectivityManager connectivity=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { return false; } else { NetworkInfo[] info=connectivity.getAllNetworkInfo(); if (info != null) { for (int i=0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } } } } else { Log.e("NetworkUtil","No context."); } return false; }
Example 58
From project HapiPodcastJ, under directory /src/info/xuluan/podcast/service/.
Source file: PodcastService.java

private int updateConnectStatus(){ log.debug("updateConnectStatus"); try { ConnectivityManager cm=(ConnectivityManager)this.getSystemService(CONNECTIVITY_SERVICE); NetworkInfo info=cm.getActiveNetworkInfo(); if (info == null) { mConnectStatus=NO_CONNECT; return mConnectStatus; } if (info.isConnected() && (info.getType() == 1)) { mConnectStatus=WIFI_CONNECT; pref_update=pref_update_wifi; return mConnectStatus; } else { mConnectStatus=MOBILE_CONNECT; pref_update=pref_update_mobile; return mConnectStatus; } } catch ( Exception e) { e.printStackTrace(); mConnectStatus=NO_CONNECT; return mConnectStatus; } }
Example 59
From project huiswerk, under directory /print/zxing-1.6/android/src/com/google/zxing/client/android/wifi/.
Source file: WifiReceiver.java

@Override public void onReceive(Context context,Intent intent){ if (intent.getAction().equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) { handleChange((SupplicantState)intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE),intent.hasExtra(WifiManager.EXTRA_SUPPLICANT_ERROR)); } else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { handleNetworkStateChanged((NetworkInfo)intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO)); } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { ConnectivityManager con=(ConnectivityManager)parent.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] s=con.getAllNetworkInfo(); for ( NetworkInfo i : s) { if (i.getTypeName().contentEquals("WIFI")) { NetworkInfo.State state=i.getState(); String ssid=mWifiManager.getConnectionInfo().getSSID(); if (state == NetworkInfo.State.CONNECTED && ssid != null) { mWifiManager.saveConfiguration(); String label=parent.getString(R.string.wifi_connected); statusView.setText(label + '\n' + ssid); Runnable delayKill=new Killer(parent); delayKill.run(); } if (state == NetworkInfo.State.DISCONNECTED) { Log.d(TAG,"Got state: " + state + " for ssid: "+ ssid); parent.gotError(); } } } } }
Example 60
From project IOCipherServer, under directory /src/info/guardianproject/iocipher/server/.
Source file: IOCipherServerActivity.java

private String getNetworkAddress(){ ConnectivityManager connMgr=(ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE); final android.net.NetworkInfo wifi=connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); final android.net.NetworkInfo mobile=connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifi.isAvailable()) { WifiManager myWifiManager=(WifiManager)getSystemService(WIFI_SERVICE); WifiInfo myWifiInfo=myWifiManager.getConnectionInfo(); int ip=myWifiInfo.getIpAddress(); String ipString=android.text.format.Formatter.formatIpAddress(ip); Log.w(TAG,"Wifi address: " + ipString); return ipString; } else if (mobile.isAvailable()) { Log.w(TAG,"No wifi available (mobile, yes)"); } else { Log.w(TAG,"No network available"); } return null; }
Example 61
From project mobilis, under directory /MXA/src/de/tudresden/inf/rn/mobilis/mxa/.
Source file: NetworkMonitor.java

@Override public void onReceive(Context context,Intent intent){ String action=intent.getAction(); if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { ConnectivityManager connectivityManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo=connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo != null && activeNetworkInfo.getReason() == null) { return; } Log.v(TAG,"Connectivity change"); if (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) { mConnected=false; } else { mConnected=true; if (connectScheduled) { connectScheduled=false; mXMPPRemoteService.connect(); } else { mXMPPRemoteService.reconnect(); } } if (activeNetworkInfo != null) { Log.v(TAG,activeNetworkInfo.toString()); Log.v(TAG,activeNetworkInfo.getDetailedState().toString()); } Log.v(TAG,"isfailover: " + intent.getExtras().getBoolean(ConnectivityManager.EXTRA_IS_FAILOVER)); if (intent.getExtras().getParcelable(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO) != null) Log.v(TAG,"oni: " + intent.getExtras().getParcelable(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO).toString()); } }
Example 62
From project mp3tunes-android, under directory /src/com/mp3tunes/android/service/.
Source file: Mp3tunesService.java

private int chooseBitrate(){ int bitrate=Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(this).getString("bitrate","-1")); if (bitrate == -1) { int[] vals=getResources().getIntArray(R.array.rate_values); ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); int type=cm.getActiveNetworkInfo().getType(); if (type == ConnectivityManager.TYPE_WIFI) { bitrate=vals[4]; } else if (type == ConnectivityManager.TYPE_MOBILE) { TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); switch (tm.getNetworkType()) { case TelephonyManager.NETWORK_TYPE_UNKNOWN: case TelephonyManager.NETWORK_TYPE_GPRS: bitrate=vals[2]; break; case TelephonyManager.NETWORK_TYPE_EDGE: case TelephonyManager.NETWORK_TYPE_UMTS: bitrate=vals[3]; break; } } } return bitrate; }
Example 63
From project OAK, under directory /oak-library/src/main/java/oak/external/com/github/droidfu/http/.
Source file: BetterHttp.java

public static void updateProxySettings(){ if (appContext == null) { return; } HttpParams httpParams=httpClient.getParams(); ConnectivityManager connectivity=(ConnectivityManager)appContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo=connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return; } Log.i(LOG_TAG,nwInfo.toString()); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost=Proxy.getHost(appContext); if (proxyHost == null) { proxyHost=Proxy.getDefaultHost(); } int proxyPort=Proxy.getPort(appContext); if (proxyPort == -1) { proxyPort=Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy=new HttpHost(proxyHost,proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY,null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY,null); } }
Example 64
From project packages_apps_BlackICEControl, under directory /src/com/blackice/control/util/.
Source file: Helpers.java

/** * Checks device for network connectivity * @return If the device has data connectivity */ public static boolean isNetworkAvailable(final Context c){ boolean state=false; if (c != null) { ConnectivityManager cm=(ConnectivityManager)c.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo=cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnected()) { Log.i(TAG,"The device currently has data connectivity"); state=true; } else { Log.i(TAG,"The device does not currently have data connectivity"); state=false; } } return state; }
Example 65
From project packages_apps_ROMControl, under directory /src/com/aokp/romcontrol/util/.
Source file: Helpers.java

/** * Checks device for network connectivity * @return If the device has data connectivity */ public static boolean isNetworkAvailable(final Context c){ boolean state=false; if (c != null) { ConnectivityManager cm=(ConnectivityManager)c.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo=cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnected()) { Log.i(TAG,"The device currently has data connectivity"); state=true; } else { Log.i(TAG,"The device does not currently have data connectivity"); state=false; } } return state; }
Example 66
From project PartyWare, under directory /android/src/com/google/zxing/client/android/wifi/.
Source file: WifiReceiver.java

@Override public void onReceive(Context context,Intent intent){ if (intent.getAction().equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) { handleChange((SupplicantState)intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE),intent.hasExtra(WifiManager.EXTRA_SUPPLICANT_ERROR)); } else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { handleNetworkStateChanged((NetworkInfo)intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO)); } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { ConnectivityManager con=(ConnectivityManager)parent.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] s=con.getAllNetworkInfo(); for ( NetworkInfo i : s) { if (i.getTypeName().contentEquals("WIFI")) { NetworkInfo.State state=i.getState(); String ssid=mWifiManager.getConnectionInfo().getSSID(); if (state == NetworkInfo.State.CONNECTED && ssid != null) { mWifiManager.saveConfiguration(); String label=parent.getString(R.string.wifi_connected); statusView.setText(label + '\n' + ssid); Runnable delayKill=new Killer(parent); delayKill.run(); } if (state == NetworkInfo.State.DISCONNECTED) { Log.d(TAG,"Got state: " + state + " for ssid: "+ ssid); ((WifiActivity)parent).gotError(); } } } } }
Example 67
From project platform_packages_apps_mms, under directory /src/com/android/mms/transaction/.
Source file: Transaction.java

/** * Make sure that a network route exists to allow us to reach the host in the supplied URL, and to the MMS proxy host as well, if a proxy is used. * @param url The URL of the MMSC to which we need a route * @param settings Specifies the address of the proxy host, if any * @throws IOException if the host doesn't exist, or adding the route fails. */ private void ensureRouteToHost(String url,TransactionSettings settings) throws IOException { ConnectivityManager connMgr=(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); int inetAddr; if (settings.isProxySet()) { String proxyAddr=settings.getProxyAddress(); inetAddr=lookupHost(proxyAddr); if (inetAddr == -1) { throw new IOException("Cannot establish route for " + url + ": Unknown host"); } else { if (!connMgr.requestRouteToHost(ConnectivityManager.TYPE_MOBILE_MMS,inetAddr)) { throw new IOException("Cannot establish route to proxy " + inetAddr); } } } else { Uri uri=Uri.parse(url); inetAddr=lookupHost(uri.getHost()); if (inetAddr == -1) { throw new IOException("Cannot establish route for " + url + ": Unknown host"); } else { if (!connMgr.requestRouteToHost(ConnectivityManager.TYPE_MOBILE_MMS,inetAddr)) { throw new IOException("Cannot establish route to " + inetAddr + " for "+ url); } } } }
Example 68
From project adg-android, under directory /src/com/analysedesgeeks/android/service/impl/.
Source file: ConnectionServiceImpl.java

@Override public boolean isConnected(){ final NetworkInfo ni=connectivityManager.getActiveNetworkInfo(); if (ni == null) { final NetworkInfo wifiConnectivityInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiConnectivityInfo.isConnected() || wifiConnectivityInfo.isConnectedOrConnecting()) { return true; } return true; } else { final State state=ni.getState(); if (state.equals(State.CONNECTED) || state.equals(State.CONNECTING)) { return true; } return false; } }
Example 69
From project android-client_1, under directory /src/com/googlecode/asmack/connection/.
Source file: ConnectivityReceiver.java

@Override public void onReceive(Context context,Intent intent){ if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false)) { if (!disconnected) { Log.d(TAG,"Disconnected"); disconnected=true; } return; } if (!disconnected) { return; } disconnected=false; xmppTransportService.onConnectivityAvailable(); }
Example 70
From project android-thaiime, under directory /common/src/com/android/common/.
Source file: NetworkConnectivityListener.java

@Override public void onReceive(Context context,Intent intent){ String action=intent.getAction(); if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION) || mListening == false) { Log.w(TAG,"onReceived() called with " + mState.toString() + " and "+ intent); return; } boolean noConnectivity=intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false); if (noConnectivity) { mState=State.NOT_CONNECTED; } else { mState=State.CONNECTED; } mNetworkInfo=(NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); mOtherNetworkInfo=(NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO); mReason=intent.getStringExtra(ConnectivityManager.EXTRA_REASON); mIsFailover=intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER,false); if (DBG) { Log.d(TAG,"onReceive(): mNetworkInfo=" + mNetworkInfo + " mOtherNetworkInfo = "+ (mOtherNetworkInfo == null ? "[none]" : mOtherNetworkInfo + " noConn=" + noConnectivity)+ " mState="+ mState.toString()); } Iterator<Handler> it=mHandlers.keySet().iterator(); while (it.hasNext()) { Handler target=it.next(); Message message=Message.obtain(target,mHandlers.get(target)); target.sendMessage(message); } }
Example 71
From project android-voip-service, under directory /src/main/java/org/linphone/.
Source file: NetworkManager.java

@Override public void onReceive(Context context,Intent intent){ NetworkInfo lNetworkInfo=(NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); Log.i("Network info [",lNetworkInfo,"]"); Boolean lNoConnectivity=intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false); if (!LinphoneService.isReady()) { Log.i("Network broadcast received while Linphone service not ready"); return; } if (lNoConnectivity | ((lNetworkInfo.getState() == NetworkInfo.State.DISCONNECTED))) { LinphoneManager.getLc().setNetworkReachable(false); } else if (lNetworkInfo.getState() == NetworkInfo.State.CONNECTED) { LinphoneManager.getLc().setNetworkReachable(true); } else { } }
Example 72
From project android-xbmcremote, under directory /src/org/xbmc/android/util/.
Source file: WifiHelper.java

public int getWifiState(){ switch (mManager.getWifiState()) { case WifiManager.WIFI_STATE_UNKNOWN: Log.d(TAG,"WIFI_STATE_UNKOWN"); return WIFI_STATE_UNKNOWN; case WifiManager.WIFI_STATE_DISABLED: case WifiManager.WIFI_STATE_DISABLING: Log.d(TAG,"WIFI_STATE_DISABLED"); return WIFI_STATE_DISABLED; case WifiManager.WIFI_STATE_ENABLING: case WifiManager.WIFI_STATE_ENABLED: final WifiInfo info=mManager.getConnectionInfo(); if (info != null && info.getSSID() != null) { Log.d(TAG,"WIFI_STATE_CONNECTED to " + info.getSSID()); final NetworkInfo mWifi=mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (mWifi.isConnected()) { return WIFI_STATE_CONNECTED; } } Log.d(TAG,"WIFI_STATE_ENABLED"); return WIFI_STATE_ENABLED; } return -1; }
Example 73
public int isWiFiEnabled(){ this._connectivity=(ConnectivityManager)_application.getSystemService(Context.CONNECTIVITY_SERVICE); this._network=this._connectivity.getActiveNetworkInfo(); if ((this._network != null) && (this._network.getType() == Settings.WiFiMode)) return (this._network.getState() == State.CONNECTED) ? Settings.WiFiActive : Settings.WiFiError; else return Settings.WiFiInactive; }
Example 74
From project android_frameworks_ex, under directory /common/java/com/android/common/.
Source file: NetworkConnectivityListener.java

@Override public void onReceive(Context context,Intent intent){ String action=intent.getAction(); if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION) || mListening == false) { Log.w(TAG,"onReceived() called with " + mState.toString() + " and "+ intent); return; } boolean noConnectivity=intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false); if (noConnectivity) { mState=State.NOT_CONNECTED; } else { mState=State.CONNECTED; } mNetworkInfo=(NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); mOtherNetworkInfo=(NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO); mReason=intent.getStringExtra(ConnectivityManager.EXTRA_REASON); mIsFailover=intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER,false); if (DBG) { Log.d(TAG,"onReceive(): mNetworkInfo=" + mNetworkInfo + " mOtherNetworkInfo = "+ (mOtherNetworkInfo == null ? "[none]" : mOtherNetworkInfo + " noConn=" + noConnectivity)+ " mState="+ mState.toString()); } Iterator<Handler> it=mHandlers.keySet().iterator(); while (it.hasNext()) { Handler target=it.next(); Message message=Message.obtain(target,mHandlers.get(target)); target.sendMessage(message); } }
Example 75
From project android_packages_apps_Gallery2, under directory /src/com/android/gallery3d/util/.
Source file: ReverseGeocoder.java

public ReverseGeocoder(Context context){ mContext=context; mGeocoder=new Geocoder(mContext); mGeoCache=CacheManager.getCache(context,GEO_CACHE_FILE,GEO_CACHE_MAX_ENTRIES,GEO_CACHE_MAX_BYTES,GEO_CACHE_VERSION); mConnectivityManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); }
Example 76
From project android_packages_inputmethods_LatinIME, under directory /java/src/com/android/inputmethod/latin/.
Source file: LatinIME.java

@Override public void onReceive(Context context,Intent intent){ final String action=intent.getAction(); if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { updateRingerMode(); } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { mSubtypeSwitcher.onNetworkStateChanged(intent); } }
Example 77
From project AsmackService, under directory /src/com/googlecode/asmack/connection/.
Source file: ConnectivityReceiver.java

@Override public void onReceive(Context context,Intent intent){ if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false)) { if (!disconnected) { Log.d(TAG,"Disconnected"); disconnected=true; } return; } if (!disconnected) { return; } disconnected=false; xmppTransportService.onConnectivityAvailable(); }
Example 78
From project Bitcoin-Wallet-for-Android, under directory /wallet/src/de/schildbach/wallet/service/.
Source file: BlockchainServiceImpl.java

@Override public void onReceive(final Context context,final Intent intent){ final String action=intent.getAction(); if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) { hasConnectivity=!intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false); final String reason=intent.getStringExtra(ConnectivityManager.EXTRA_REASON); System.out.println("network is " + (hasConnectivity ? "up" : "down") + (reason != null ? ": " + reason : "")); check(); } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { final int level=intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1); final int scale=intent.getIntExtra(BatteryManager.EXTRA_SCALE,-1); final int plugged=intent.getIntExtra(BatteryManager.EXTRA_PLUGGED,0); hasPower=plugged != 0 || level > scale / 10; System.out.println("battery changed: level=" + level + "/"+ scale+ " plugged="+ plugged); check(); } else if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(action)) { hasStorage=false; System.out.println("device storage low"); check(); } else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(action)) { hasStorage=true; System.out.println("device storage ok"); check(); } }
Example 79
From project CheckIn4Me, under directory /src/com/davidivins/checkin4me/activities/.
Source file: NearbyPlaces.java

/** * GPSTimeout */ public void GPSTimeout(){ Log.i(TAG,"GPSTimeout"); cancelProgressDialog(); stopLocationListener(); NetworkInfo mobile_network_info=((ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_MOBILE); NetworkInfo wifi_network_info=((ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (((LocationManager)this.getSystemService(Context.LOCATION_SERVICE)).isProviderEnabled(LocationManager.NETWORK_PROVIDER) && (mobile_network_info.isConnectedOrConnecting() || wifi_network_info.isConnectedOrConnecting())) { network_timeout_monitor=new NetworkTimeoutMonitor(this); network_timeout_monitor.execute(); startNetworkLocationListener(); startProgressDialog("Acquiring Network Location..."); } else { NetworkTimeout(); } }
Example 80
@Override public void onReceive(Context context,Intent intent){ boolean noConnectivity=intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false); vibrator=(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); if (noConnectivity && isMyServiceRunning(context)) { context.stopService(new Intent(context,ConnectionService.class)); Toast.makeText(context,R.string.connectionTimeoutMessage,Toast.LENGTH_LONG).show(); vibrator.vibrate(300); Intent closeAllActivities=new Intent(context.getApplicationContext(),LoginScreenActivity.class); closeAllActivities.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); closeAllActivities.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.getApplicationContext().startActivity(closeAllActivities); } }
Example 81
From project droidparts, under directory /extra/src/org/droidparts/util/net/.
Source file: ConnectivityAwareExecutor.java

public ConnectivityAwareExecutor(Context ctx,int slowMobileThreads,int fastMobileThreads,int wifiThreads){ super(1,1,0,TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(),new ExecutorThreadFactory()); this.ctx=ctx.getApplicationContext(); this.slowMobileThreads=slowMobileThreads; this.fastMobileThreads=fastMobileThreads; this.wifiThreads=wifiThreads; connectivityManager=(ConnectivityManager)ctx.getSystemService(CONNECTIVITY_SERVICE); ctx.registerReceiver(connectivityReceiver,new IntentFilter(CONNECTIVITY_ACTION)); }
Example 82
From project ICS_LatinIME_QHD, under directory /java/src/com/android/inputmethod/latin/.
Source file: LatinIME.java

@Override public void onReceive(Context context,Intent intent){ final String action=intent.getAction(); if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { updateRingerMode(); } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { mSubtypeSwitcher.onNetworkStateChanged(intent); } }
Example 83
From project incubator-cordova-android, under directory /framework/src/org/apache/cordova/.
Source file: NetworkManager.java

/** * Sets the context of the Command. This can then be used to do things like get file paths associated with the Activity. * @param cordova The context of the main Activity. * @param webView The CordovaWebView Cordova is running in. */ public void initialize(CordovaInterface cordova,CordovaWebView webView){ super.initialize(cordova,webView); this.sockMan=(ConnectivityManager)cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); this.connectionCallbackContext=null; IntentFilter intentFilter=new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); if (this.receiver == null) { this.receiver=new BroadcastReceiver(){ @SuppressWarnings("deprecation") @Override public void onReceive( Context context, Intent intent){ if (NetworkManager.this.webView != null) updateConnectionInfo((NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO)); } } ; cordova.getActivity().registerReceiver(this.receiver,intentFilter); this.registered=true; } }
Example 84
/** * {@inheritDoc} */ @Override public void onCreate(){ super.onCreate(); registerReceiver(mReceiver,new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); mSettings=PreferenceManager.getDefaultSharedPreferences(this); mSettings.registerOnSharedPreferenceChangeListener(mPreferenceListener); if (mSettings.getBoolean(BeemApplication.USE_AUTO_AWAY_KEY,false)) { mOnOffReceiverIsRegistered=true; registerReceiver(mOnOffReceiver,new IntentFilter(Intent.ACTION_SCREEN_OFF)); registerReceiver(mOnOffReceiver,new IntentFilter(Intent.ACTION_SCREEN_ON)); } String tmpJid=mSettings.getString(BeemApplication.ACCOUNT_USERNAME_KEY,"").trim() + "@pvp.net"; mLogin=StringUtils.parseName(tmpJid); mPassword="AIR_" + mSettings.getString(BeemApplication.ACCOUNT_PASSWORD_KEY,""); mPort=DEFAULT_XMPP_PORT; mService=StringUtils.parseServer(tmpJid); mHost=mService; if (mSettings.getBoolean("settings_key_specific_server",false)) { mHost=mSettings.getString("settings_key_xmpp_server","").trim(); if ("".equals(mHost)) mHost=mService; String tmpPort=mSettings.getString("settings_key_xmpp_port","5223"); if (!"".equals(tmpPort)) mPort=Integer.parseInt(tmpPort); } if (mSettings.getBoolean(BeemApplication.FULL_JID_LOGIN_KEY,false) || "gmail.com".equals(mService) || "googlemail.com".equals(mService)) { mLogin=tmpJid; } initConnectionConfig(); configure(ProviderManager.getInstance()); mNotificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); mConnection=new XmppConnectionAdapter(mConnectionConfiguration,mLogin,mPassword,this); Roster.setDefaultSubscriptionMode(SubscriptionMode.manual); mBind=new XmppFacade(mConnection); Log.d(TAG,"Create BeemService"); }
Example 85
From project MobiPerf, under directory /android/src/com/mobiperf/util/.
Source file: PhoneUtils.java

/** * Returns the network that the phone is on (e.g. Wifi, Edge, GPRS, etc). */ public String getNetwork(){ initNetwork(); NetworkInfo networkInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED) { return NETWORK_WIFI; } else { return getTelephonyNetworkType(); } }
Example 86
From project mythmote, under directory /src/tkj/android/homecontrol/mythmote/.
Source file: MythCom.java

/** * Connects to the given address and port. Any existing connection will be broken first */ public void Connect(FrontendLocation frontend){ int updateInterval=_parent.getSharedPreferences(MythMotePreferences.MYTHMOTE_SHARED_PREFERENCES_ID,Context.MODE_PRIVATE).getInt(MythMotePreferences.PREF_STATUS_UPDATE_INTERVAL,5000); scheduleUpdateTimer(updateInterval); _conMgr=(ConnectivityManager)_parent.getSystemService(Context.CONNECTIVITY_SERVICE); _frontend=frontend; _toast=Toast.makeText(_parent.getApplicationContext(),R.string.attempting_to_connect_str,Toast.LENGTH_SHORT); _toast.setGravity(Gravity.CENTER,0,0); _toast.show(); this.setStatus("Connecting",STATUS_CONNECTING); this.connectSocket(); }
Example 87
From project nuxeo-android, under directory /nuxeo-android-connector/src/main/java/org/nuxeo/android/context/.
Source file: NuxeoContext.java

public NuxeoContext(Context androidContext){ this.androidContext=androidContext; sqlStateManager=new SQLStateManager(androidContext); blobStore=new BlobStoreManager(androidContext); serverConfig=new NuxeoServerConfig(androidContext); networkStatus=new NuxeoNetworkStatus(androidContext,serverConfig,(ConnectivityManager)androidContext.getSystemService(Context.CONNECTIVITY_SERVICE)); androidContext.registerReceiver(new NetworkStatusBroadCastReceiver(networkStatus),new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); IntentFilter filter=new IntentFilter(); filter.addAction(NuxeoBroadcastMessages.NUXEO_SETTINGS_CHANGED); filter.addAction(NuxeoBroadcastMessages.NUXEO_SERVER_CONNECTIVITY_CHANGED); androidContext.registerReceiver(this,filter); getNuxeoClient(); }
Example 88
From project openpomo, under directory /src/it/unibz/pomodroid/services/.
Source file: XmlRpcClient.java

/** * @return boolean return true if the application can access the internet */ public static boolean isInternetAvailable(Context context){ NetworkInfo connectionAvailable=((ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo(); if (connectionAvailable == null || !connectionAvailable.isConnected()) { return false; } if (connectionAvailable.isRoaming()) { return true; } return true; }
Example 89
From project platform_frameworks_ex, under directory /common/java/com/android/common/.
Source file: NetworkConnectivityListener.java

@Override public void onReceive(Context context,Intent intent){ String action=intent.getAction(); if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION) || mListening == false) { Log.w(TAG,"onReceived() called with " + mState.toString() + " and "+ intent); return; } boolean noConnectivity=intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false); if (noConnectivity) { mState=State.NOT_CONNECTED; } else { mState=State.CONNECTED; } mNetworkInfo=(NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); mOtherNetworkInfo=(NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO); mReason=intent.getStringExtra(ConnectivityManager.EXTRA_REASON); mIsFailover=intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER,false); if (DBG) { Log.d(TAG,"onReceive(): mNetworkInfo=" + mNetworkInfo + " mOtherNetworkInfo = "+ (mOtherNetworkInfo == null ? "[none]" : mOtherNetworkInfo + " noConn=" + noConnectivity)+ " mState="+ mState.toString()); } Iterator<Handler> it=mHandlers.keySet().iterator(); while (it.hasNext()) { Handler target=it.next(); Message message=Message.obtain(target,mHandlers.get(target)); target.sendMessage(message); } }
Example 90
From project platform_frameworks_support, under directory /v4/gingerbread/android/support/v4/net/.
Source file: ConnectivityManagerCompatGingerbread.java

public static boolean isActiveNetworkMetered(ConnectivityManager cm){ final NetworkInfo info=cm.getActiveNetworkInfo(); if (info == null) { return true; } final int type=info.getType(); switch (type) { case TYPE_MOBILE: case TYPE_MOBILE_DUN: case TYPE_MOBILE_HIPRI: case TYPE_MOBILE_MMS: case TYPE_MOBILE_SUPL: case TYPE_WIMAX: return true; case TYPE_WIFI: return false; default : return true; } }
Example 91
From project platform_packages_apps_Gallery2_1, under directory /src/com/android/gallery3d/util/.
Source file: ReverseGeocoder.java

public ReverseGeocoder(Context context){ mContext=context; mGeocoder=new Geocoder(mContext); mGeoCache=CacheManager.getCache(context,GEO_CACHE_FILE,GEO_CACHE_MAX_ENTRIES,GEO_CACHE_MAX_BYTES,GEO_CACHE_VERSION); mConnectivityManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); }