Java Code Examples for android.net.NetworkInfo

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

  18 
vote

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 Absolute-Android-RSS, under directory /src/com/AA/Other/.

Source file: RSSParse.java

  18 
vote

/** 
 * 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 3

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/activity/.

Source file: HeatMapActivity.java

  18 
vote

private void checkConnection(){
  NetworkInfo activeNetworkInfo=connectivityManager.getActiveNetworkInfo();
  if (activeNetworkInfo == null || !activeNetworkInfo.isConnectedOrConnecting()) {
    Toast.makeText(this,R.string.no_internet,Toast.LENGTH_SHORT).show();
  }
}
 

Example 4

From project Airports, under directory /src/com/nadmm/airports/utils/.

Source file: NetworkUtils.java

  18 
vote

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 5

From project aksunai, under directory /src/org/androidnerds/app/aksunai/.

Source file: Aksunai.java

  18 
vote

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 6

From project android-flash-cards, under directory /src/org/thomasamsler/android/flashcards/activity/.

Source file: MainActivity.java

  18 
vote

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 7

From project Android-RTMP, under directory /android-ffmpeg-prototype/src/com/camundo/util/.

Source file: NetworkUtils.java

  18 
vote

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 8

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/deviceinfo/.

Source file: Status.java

  18 
vote

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: SipCallOptionHandler.java

  18 
vote

private boolean isNetworkConnected(){
  ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
  if (cm != null) {
    NetworkInfo ni=cm.getActiveNetworkInfo();
    if ((ni == null) || !ni.isConnected())     return false;
    return ((ni.getType() == ConnectivityManager.TYPE_WIFI) || !SipManager.isSipWifiOnly(this));
  }
  return false;
}
 

Example 10

From project BBC-News-Reader, under directory /src/com/digitallizard/bbcnewsreader/.

Source file: ResourceService.java

  18 
vote

boolean isOnline(){
  ConnectivityManager manager=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo info=manager.getActiveNetworkInfo();
  if (info != null) {
    return info.isConnected();
  }
 else {
    return false;
  }
}
 

Example 11

From project BF3-Battlelog, under directory /src/com/ninetwozero/battlelog/broadcastreceiver/.

Source file: NetworkReceiver.java

  18 
vote

@Override public void onReceive(Context context,Intent intent){
  AlarmManager alarmManager=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
  NetworkInfo networkInfo=(NetworkInfo)intent.getExtras().get("networkInfo");
  alarmManager.cancel(PendingIntent.getService(context,0,new Intent(context,BattlelogService.class),0));
  if (networkInfo.isConnected()) {
    SharedPreferences sharedPreferences=PreferenceManager.getDefaultSharedPreferences(context);
    if (!sharedPreferences.getString(Constants.SP_BL_PROFILE_PASSWORD,"").equals("")) {
      alarmManager.setInexactRepeating(0,0,sharedPreferences.getInt(Constants.SP_BL_INTERVAL_SERVICE,0),PendingIntent.getService(context,0,new Intent(context,BattlelogService.class),0));
    }
  }
}
 

Example 12

From project bitfluids, under directory /src/main/java/at/bitcoin_austria/bitfluids/trafficSignal/.

Source file: TrafficSignal.java

  18 
vote

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 13

From project CHMI, under directory /src/org/kaldax/app/chmi/.

Source file: CHMI.java

  18 
vote

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 14

From project connectbot, under directory /src/sk/vx/connectbot/service/.

Source file: ConnectivityReceiver.java

  18 
vote

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 15

From project creamed_glacier_app_settings, under directory /src/com/android/settings/deviceinfo/.

Source file: Status.java

  18 
vote

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 16

From project dmix, under directory /MPDroid/src/com/namelessdev/mpdroid/helpers/.

Source file: MPDConnectionHandler.java

  18 
vote

@Override public void onReceive(Context context,Intent intent){
  String action=intent.getAction();
  if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
    System.out.println("WIFI-STATE:" + intent.getAction().toString());
    System.out.println("WIFI-STATE:" + (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,WifiManager.WIFI_STATE_UNKNOWN)));
  }
 else   if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
    System.out.println("NETW-STATE:" + intent.getAction().toString());
    NetworkInfo networkInfo=(NetworkInfo)intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    System.out.println("NETW-STATE: Connected: " + networkInfo.isConnected());
    System.out.println("NETW-STATE: Connected: " + networkInfo.getState().toString());
  }
}
 

Example 17

From project fanfoudroid, under directory /src/com/ch_linghu/fanfoudroid/.

Source file: TwitterApplication.java

  18 
vote

public String getNetworkType(){
  ConnectivityManager connectivityManager=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo activeNetInfo=connectivityManager.getActiveNetworkInfo();
  if (activeNetInfo != null) {
    return activeNetInfo.getExtraInfo();
  }
 else {
    return null;
  }
}
 

Example 18

From project GeekAlarm, under directory /android/src/com/geek_alarm/android/.

Source file: Utils.java

  18 
vote

/** 
 * 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 19

From project Gibberbot, under directory /src/info/guardianproject/otr/app/im/service/.

Source file: RemoteImService.java

  18 
vote

private Map<String,String> loadProviderSettings(long providerId){
  ContentResolver cr=getContentResolver();
  Map<String,String> settings=Imps.ProviderSettings.queryProviderSettings(cr,providerId);
  NetworkInfo networkInfo=mNetworkConnectivityListener.getNetworkInfo();
  return settings;
}
 

Example 20

From project groundy, under directory /src/main/java/com/codeslap/groundy/.

Source file: DeviceStatus.java

  18 
vote

/** 
 * 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 21

From project ignition, under directory /ignition-location/ignition-location-lib/src/com/github/ignition/location/receivers/.

Source file: IgnitedConnectivityChangedReceiver.java

  18 
vote

@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 22

From project incubator-cordova-android, under directory /framework/src/org/apache/cordova/.

Source file: NetworkManager.java

  18 
vote

/** 
 * Executes the request and returns PluginResult.
 * @param action            The action to execute.
 * @param args              JSONArry of arguments for the plugin.
 * @param callbackContext   The callback id used when calling back into JavaScript.
 * @return                  True if the action was valid, false otherwise.
 */
public boolean execute(String action,JSONArray args,CallbackContext callbackContext){
  if (action.equals("getConnectionInfo")) {
    this.connectionCallbackContext=callbackContext;
    NetworkInfo info=sockMan.getActiveNetworkInfo();
    PluginResult pluginResult=new PluginResult(PluginResult.Status.OK,this.getConnectionInfo(info));
    pluginResult.setKeepCallback(true);
    callbackContext.sendPluginResult(pluginResult);
    return true;
  }
  return false;
}
 

Example 23

From project iosched_3, under directory /android/src/com/google/android/apps/iosched/ui/.

Source file: AccountActivity.java

  18 
vote

@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 24

From project k-9, under directory /src/com/fsck/k9/helper/.

Source file: Utility.java

  18 
vote

/** 
 * 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 25

From project Locast-Android, under directory /src/edu/mit/mobile/android/locast/widget/.

Source file: RemoteTagsAdapter.java

  18 
vote

public void refreshTags(){
  final NetworkInfo activeNet=cm.getActiveNetworkInfo();
  final boolean hasNetConnection=activeNet != null && activeNet.isConnected();
  if (hasNetConnection && !updating && (lastUpdated == 0 || (new Date().getTime() - lastUpdated > cacheAge))) {
    new TagLoaderTask().execute();
  }
}
 

Example 26

From project MobiPerf, under directory /android/src/com/mobiperf/util/.

Source file: PhoneUtils.java

  18 
vote

/** 
 * 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 27

From project Novocation, under directory /core/src/main/java/com/novoda/location/receiver/.

Source file: UnregisterPassiveListenerOnLostConnectivity.java

  18 
vote

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 28

From project official-android-app--DEPRECATED-, under directory /src/com/plancake/android/app/.

Source file: Utils.java

  18 
vote

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 29

From project OpenAndroidWeather, under directory /OpenAndroidWeather/src/no/firestorm/misc/.

Source file: CheckInternetStatus.java

  18 
vote

/** 
 * 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 30

From project openpomo, under directory /src/it/unibz/pomodroid/services/.

Source file: XmlRpcClient.java

  18 
vote

/** 
 * @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 31

From project packages_apps_Phone_1, under directory /src/com/android/phone/.

Source file: SipCallOptionHandler.java

  18 
vote

private boolean isNetworkConnected(){
  ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
  if (cm != null) {
    NetworkInfo ni=cm.getActiveNetworkInfo();
    if ((ni == null) || !ni.isConnected())     return false;
    return ((ni.getType() == ConnectivityManager.TYPE_WIFI) || !SipManager.isSipWifiOnly(this));
  }
  return false;
}
 

Example 32

From project platform_packages_apps_CytownPhone, under directory /src/com/android/phone/.

Source file: SipCallOptionHandler.java

  18 
vote

private boolean isNetworkConnected(){
  ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
  if (cm != null) {
    NetworkInfo ni=cm.getActiveNetworkInfo();
    if ((ni == null) || !ni.isConnected())     return false;
    return ((ni.getType() == ConnectivityManager.TYPE_WIFI) || !SipManager.isSipWifiOnly(this));
  }
  return false;
}
 

Example 33

From project platform_packages_apps_phone, under directory /src/com/android/phone/.

Source file: SipCallOptionHandler.java

  18 
vote

private boolean isNetworkConnected(){
  ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
  if (cm != null) {
    NetworkInfo ni=cm.getActiveNetworkInfo();
    if ((ni == null) || !ni.isConnected())     return false;
    return ((ni.getType() == ConnectivityManager.TYPE_WIFI) || !SipManager.isSipWifiOnly(this));
  }
  return false;
}
 

Example 34

From project platform_packages_apps_settings, under directory /src/com/android/settings/deviceinfo/.

Source file: Status.java

  18 
vote

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 35

From project platform_packages_providers_downloadprovider, under directory /src/com/android/providers/downloads/.

Source file: RealSystemFacade.java

  18 
vote

public NetworkInfo getActiveNetworkInfo(int uid){
  ConnectivityManager connectivity=(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
  if (connectivity == null) {
    Log.w(Constants.TAG,"couldn't get connectivity manager");
    return null;
  }
  final NetworkInfo activeInfo=connectivity.getActiveNetworkInfoForUid(uid);
  if (activeInfo == null && Constants.LOGVV) {
    Log.v(Constants.TAG,"network is not available");
  }
  return activeInfo;
}
 

Example 36

From project reddit-is-fun, under directory /src/com/andrewshu/android/reddit/common/.

Source file: Common.java

  18 
vote

public static boolean shouldLoadThumbnails(Activity activity,RedditSettings settings){
  boolean thumbOkay=true;
  if (settings.isLoadThumbnailsOnlyWifi()) {
    thumbOkay=false;
    ConnectivityManager connMan=(ConnectivityManager)activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo=connMan.getActiveNetworkInfo();
    if (netInfo != null && netInfo.getType() == ConnectivityManager.TYPE_WIFI && netInfo.isConnected()) {
      thumbOkay=true;
    }
  }
  return settings.isLoadThumbnails() && thumbOkay;
}
 

Example 37

From project roman10-android-tutorial, under directory /dash/src/roman10/utils/.

Source file: EnvUtils.java

  18 
vote

public static boolean isOnline(Context pContext){
  ConnectivityManager cm=(ConnectivityManager)pContext.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo ni=cm.getActiveNetworkInfo();
  if (ni == null) {
    return false;
  }
 else {
    return ni.isConnected();
  }
}
 

Example 38

From project rozkladpkp-android, under directory /src/org/tyszecki/rozkladpkp/.

Source file: CommonUtils.java

  18 
vote

public static boolean onlineCheck(String msgError,boolean silent){
  ConnectivityManager cm=(ConnectivityManager)RozkladPKPApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo netInfo=cm.getActiveNetworkInfo();
  if (netInfo != null && netInfo.isConnectedOrConnecting()) {
    return true;
  }
  if (!silent)   Toast.makeText(RozkladPKPApplication.getAppContext(),msgError,Toast.LENGTH_SHORT).show();
  return false;
}
 

Example 39

From project Sage-Mobile-Calc, under directory /src/org/connectbot/service/.

Source file: ConnectivityReceiver.java

  18 
vote

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 40

From project SanDisk-HQME-SDK, under directory /projects/HqmeService/project/src/com/hqme/cm/core/.

Source file: RULE_ROAMING.java

  18 
vote

@Override public void init(Context context){
  ConnectivityManager cm=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo networkInfo=cm.getActiveNetworkInfo();
  if (networkInfo != null) {
    sIsConnected=networkInfo.isConnected();
    if (sIsConnected) {
      if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        sMobileSession=true;
      }
      sIsRoaming=networkInfo.isRoaming();
    }
  }
  super.init(context);
}
 

Example 41

From project SchoolPlanner4Untis, under directory /src/edu/htl3r/schoolplanner/.

Source file: SchoolPlannerApp.java

  18 
vote

@Override public void onCreate(){
  super.onCreate();
  initBackend();
  IntentFilter filter=new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
  registerReceiver(new BroadcastReceiver(){
    @Override public void onReceive(    Context context,    Intent intent){
      NetworkInfo info=intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
      setNetworkAvailable(info.isConnectedOrConnecting());
    }
  }
,filter);
}
 

Example 42

From project SeriesGuide, under directory /AndroidUtils/src/com/uwetrottmann/androidutils/.

Source file: AndroidUtils.java

  18 
vote

/** 
 * Whether there is any network with a usable connection.
 * @param context
 * @return
 */
public static boolean isNetworkConnected(Context context){
  ConnectivityManager connectivityManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo activeNetworkInfo=connectivityManager.getActiveNetworkInfo();
  if (activeNetworkInfo != null) {
    return activeNetworkInfo.isConnected();
  }
  return false;
}
 

Example 43

From project ServalMaps, under directory /src/org/servalproject/maps/utils/.

Source file: HttpUtils.java

  18 
vote

/** 
 * check to see if the device is online, ie. has a valid Internet connection
 * @param context a context used to gain access to system resources
 * @return true if there is an Internet connection, false if there isn't
 */
public static boolean isOnline(Context context){
  ConnectivityManager mConnectivityManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo mNetworkInfo=mConnectivityManager.getActiveNetworkInfo();
  if (mNetworkInfo != null && mNetworkInfo.isConnected()) {
    return true;
  }
 else {
    return false;
  }
}
 

Example 44

From project Speedometer, under directory /android/src/com/google/wireless/speed/speedometer/util/.

Source file: PhoneUtils.java

  18 
vote

/** 
 * 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 45

From project SqueezeControl, under directory /src/com/squeezecontrol/.

Source file: ServiceUtils.java

  18 
vote

/** 
 * Are we connected to either WiFi or Ethernet? TODO Figure out what TYPE_DUMMY is. TODO Look for a better test for "are we on the emulator".  Maybe it should be "is this a dev build"? XXX??? Testing for emulator makes it hard to verify that the wifi test is working.
 * @return true if the network is valid, or if we appear to be runningon the emulator.
 */
public static boolean validNetworkAvailable(Context context){
  if ("sdk".equals(android.os.Build.PRODUCT)) {
    return true;
  }
  ConnectivityManager cmgr=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo activeNetwork=cmgr.getActiveNetworkInfo();
  return null != activeNetwork && (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI || (ethernetSupported && activeNetwork.getType() == TYPE_ETHERNET));
}
 

Example 46

From project subsonic, under directory /subsonic-android/src/github/daneren2005/dsub/util/.

Source file: Util.java

  18 
vote

public static int getMaxBitrate(Context context){
  ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo networkInfo=manager.getActiveNetworkInfo();
  if (networkInfo == null) {
    return 0;
  }
  boolean wifi=networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
  SharedPreferences prefs=getPreferences(context);
  return Integer.parseInt(prefs.getString(wifi ? Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI : Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE,"0"));
}
 

Example 47

From project Subsonic-Android, under directory /src/net/sourceforge/subsonic/androidapp/util/.

Source file: Util.java

  18 
vote

public static int getMaxBitrate(Context context){
  ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo networkInfo=manager.getActiveNetworkInfo();
  if (networkInfo == null) {
    return 0;
  }
  boolean wifi=networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
  SharedPreferences prefs=getPreferences(context);
  return Integer.parseInt(prefs.getString(wifi ? Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI : Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE,"0"));
}
 

Example 48

From project subsonic_1, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/util/.

Source file: Util.java

  18 
vote

public static int getMaxBitrate(Context context){
  ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo networkInfo=manager.getActiveNetworkInfo();
  if (networkInfo == null) {
    return 0;
  }
  boolean wifi=networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
  SharedPreferences prefs=getPreferences(context);
  return Integer.parseInt(prefs.getString(wifi ? Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI : Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE,"0"));
}
 

Example 49

From project subsonic_2, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/util/.

Source file: Util.java

  18 
vote

public static int getMaxBitrate(Context context){
  ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo networkInfo=manager.getActiveNetworkInfo();
  if (networkInfo == null) {
    return 0;
  }
  boolean wifi=networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
  SharedPreferences prefs=getPreferences(context);
  return Integer.parseInt(prefs.getString(wifi ? Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI : Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE,"0"));
}
 

Example 50

From project Supersonic, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/util/.

Source file: Util.java

  18 
vote

public static int getMaxBitrate(Context context){
  ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo networkInfo=manager.getActiveNetworkInfo();
  if (networkInfo == null) {
    return 0;
  }
  boolean wifi=networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
  SharedPreferences prefs=getPreferences(context);
  return Integer.parseInt(prefs.getString(wifi ? Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI : Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE,"0"));
}
 

Example 51

From project SyncMyPix, under directory /src/com/nloko/android/.

Source file: Utils.java

  18 
vote

public static boolean hasInternetConnection(Context context){
  if (context == null) {
    throw new IllegalArgumentException("context");
  }
  ConnectivityManager connMgr=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo info=connMgr.getActiveNetworkInfo();
  return (info != null && info.isConnected());
}
 

Example 52

From project TextSecure, under directory /src/org/thoughtcrime/securesms/service/.

Source file: MmscProcessor.java

  18 
vote

protected boolean isConnected(){
  NetworkInfo info=connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
  Log.w("MmsService","NetworkInfo: " + info);
  if ((info == null) || (info.getType() != TYPE_MOBILE_MMS) || !info.isConnected())   return false;
  return true;
}
 

Example 53

From project Traktoid, under directory /Traktoid/src/com/florianmski/tracktoid/.

Source file: Utils.java

  18 
vote

public static final boolean isOnline(Context context){
  if (context == null)   return false;
  ConnectivityManager cm=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo netInfo=cm.getActiveNetworkInfo();
  if (netInfo != null && netInfo.isConnectedOrConnecting())   return true;
  return false;
}
 

Example 54

From project tshirtslayer_android, under directory /src/com/tshirtslayer/.

Source file: deliveryService.java

  18 
vote

public boolean isOnline(){
  ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo netInfo=cm.getActiveNetworkInfo();
  if (netInfo != null && netInfo.isConnectedOrConnecting()) {
    return true;
  }
  return false;
}
 

Example 55

From project UDJ-Android-Client, under directory /src/org/klnusbaum/udj/.

Source file: Utils.java

  18 
vote

public static boolean isNetworkAvailable(Context context){
  ConnectivityManager cm=((ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE));
  NetworkInfo info=cm.getActiveNetworkInfo();
  if (info != null && info.isConnected()) {
    return true;
  }
  return false;
}
 

Example 56

From project Ushahidi_Android, under directory /Core/src/com/ushahidi/android/app/net/.

Source file: MainHttpClient.java

  18 
vote

/** 
 * Is there internet connection
 */
public boolean isConnected(){
  ConnectivityManager connectivity=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  final NetworkInfo networkInfo;
  networkInfo=connectivity.getActiveNetworkInfo();
  if (networkInfo != null && networkInfo.isConnected() && networkInfo.isAvailable()) {
    return true;
  }
  return false;
}
 

Example 57

From project websms-api, under directory /src/de/ub0r/android/websms/connector/common/.

Source file: Utils.java

  18 
vote

/** 
 * Checks if there is a data network available. Requires ACCESS_NETWORK_STATE permission.
 * @param context {@link Context}
 * @return true if a data network is available
 */
public static boolean isNetworkAvailable(final Context context){
  try {
    ConnectivityManager mgr=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo net=mgr.getActiveNetworkInfo();
    return net != null && net.isConnected();
  }
 catch (  SecurityException ex) {
    return true;
  }
}
 

Example 58

From project adg-android, under directory /src/com/analysedesgeeks/android/service/impl/.

Source file: ConnectionServiceImpl.java

  17 
vote

@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 59

From project android-thaiime, under directory /latinime/src/com/sugree/inputmethod/latin/.

Source file: SubtypeSwitcher.java

  17 
vote

private void initialize(LatinIME service){
  mService=service;
  mResources=service.getResources();
  mImm=InputMethodManagerCompatWrapper.getInstance();
  mConnectivityManager=(ConnectivityManager)service.getSystemService(Context.CONNECTIVITY_SERVICE);
  mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
  mEnabledLanguagesOfCurrentInputMethod.clear();
  mSystemLocale=null;
  mInputLocale=null;
  mInputLocaleStr=null;
  mCurrentSubtype=null;
  mAllEnabledSubtypesOfCurrentInputMethod=null;
  mVoiceInputWrapper=null;
  final NetworkInfo info=mConnectivityManager.getActiveNetworkInfo();
  mIsNetworkConnected=(info != null && info.isConnected());
}
 

Example 60

From project android-voip-service, under directory /src/main/java/org/linphone/.

Source file: NetworkManager.java

  17 
vote

@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 61

From project android-xbmcremote, under directory /src/org/xbmc/android/util/.

Source file: WifiHelper.java

  17 
vote

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 62

From project androidpn, under directory /androidpn-client/src/org/androidpn/client/.

Source file: ConnectivityReceiver.java

  17 
vote

@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 63

From project android_packages_apps_Exchange, under directory /src/com/android/exchange/.

Source file: AbstractSyncService.java

  17 
vote

/** 
 * 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 64

From project android_packages_inputmethods_LatinIME, under directory /java/src/com/android/inputmethod/latin/.

Source file: SubtypeSwitcher.java

  17 
vote

private void initialize(LatinIME service){
  mService=service;
  mResources=service.getResources();
  mImm=InputMethodManagerCompatWrapper.getInstance();
  mConnectivityManager=(ConnectivityManager)service.getSystemService(Context.CONNECTIVITY_SERVICE);
  mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
  mEnabledLanguagesOfCurrentInputMethod.clear();
  mSystemLocale=null;
  mInputLocale=null;
  mInputLocaleStr=null;
  mCurrentSubtype=null;
  mAllEnabledSubtypesOfCurrentInputMethod=null;
  mVoiceInputWrapper=null;
  final NetworkInfo info=mConnectivityManager.getActiveNetworkInfo();
  mIsNetworkConnected=(info != null && info.isConnected());
}
 

Example 65

From project Cafe, under directory /webapp/src/org/openqa/selenium/android/.

Source file: NetworkStateHandler.java

  17 
vote

public NetworkStateHandler(Activity activity,final WebView view){
  this.activity=activity;
  this.view=view;
  ConnectivityManager cm=(ConnectivityManager)activity.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo info=cm.getActiveNetworkInfo();
  if (info != null) {
    isConnected=info.isConnected();
    isNetworkUp=info.isAvailable();
  }
  filter=new IntentFilter();
  filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
  receiver=new BroadcastReceiver(){
    public void onReceive(    Context context,    Intent intent){
      if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
        NetworkInfo info=intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
        String typeName=info.getTypeName();
        String subType=info.getSubtypeName();
        isConnected=info.isConnected();
        if (view != null) {
          try {
            Method setNetworkType=view.getClass().getMethod("setNetworkType",String.class,String.class);
            setNetworkType.invoke(view,typeName,(subType == null ? "" : subType));
            boolean noConnection=intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false);
            onNetworkChange(!noConnection);
          }
 catch (          Exception e) {
            throw new RuntimeException(e);
          }
        }
      }
    }
  }
;
}
 

Example 66

From project CheckIn4Me, under directory /src/com/davidivins/checkin4me/activities/.

Source file: NearbyPlaces.java

  17 
vote

/** 
 * 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 67

From project DownloadProvider, under directory /src/com/mozillaonline/providers/downloads/.

Source file: DownloadReceiver.java

  17 
vote

public void onReceive(Context context,Intent intent){
  if (mSystemFacade == null) {
    mSystemFacade=new RealSystemFacade(context);
  }
  String action=intent.getAction();
  if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
    startService(context);
  }
 else   if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
    NetworkInfo info=(NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
    if (info != null && info.isConnected()) {
      startService(context);
    }
  }
 else   if (action.equals(Constants.ACTION_RETRY)) {
    startService(context);
  }
 else   if (action.equals(Constants.ACTION_OPEN) || action.equals(Constants.ACTION_LIST) || action.equals(Constants.ACTION_HIDE)) {
    handleNotificationBroadcast(context,intent);
  }
}
 

Example 68

From project droid-fu, under directory /src/main/java/com/github/droidfu/http/.

Source file: BetterHttp.java

  17 
vote

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 69

From project droidparts, under directory /extra/src/org/droidparts/util/net/.

Source file: ConnectivityAwareExecutor.java

  17 
vote

private void detemineNetworTypeAndUpdatePoolSize(){
  try {
    NetworkInfo netInfo=connectivityManager.getActiveNetworkInfo();
    int threadCount;
switch (netInfo.getType()) {
case TYPE_MOBILE:
      if (netInfo.getSubtype() < 3) {
        threadCount=slowMobileThreads;
      }
 else {
        threadCount=fastMobileThreads;
      }
    break;
case TYPE_WIMAX:
  threadCount=fastMobileThreads;
break;
case TYPE_WIFI:
threadCount=wifiThreads;
break;
default :
threadCount=1;
}
L.i("Pool size: " + threadCount);
setCorePoolSize(threadCount);
setMaximumPoolSize(threadCount);
}
 catch (SecurityException e) {
L.e("'android.permission.ACCESS_NETWORK_STATE' required.");
}
catch (Exception e) {
L.e(e);
}
}
 

Example 70

From project FileExplorer, under directory /src/net/micode/fileexplorer/.

Source file: FTPServerService.java

  17 
vote

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 71

From project HapiPodcastJ, under directory /src/info/xuluan/podcast/service/.

Source file: PodcastService.java

  17 
vote

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 72

From project ICS_LatinIME_QHD, under directory /java/src/com/android/inputmethod/latin/.

Source file: SubtypeSwitcher.java

  17 
vote

private void initialize(LatinIME service){
  mService=service;
  mResources=service.getResources();
  mImm=InputMethodManagerCompatWrapper.getInstance();
  mConnectivityManager=(ConnectivityManager)service.getSystemService(Context.CONNECTIVITY_SERVICE);
  mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
  mEnabledLanguagesOfCurrentInputMethod.clear();
  mSystemLocale=null;
  mInputLocale=null;
  mInputLocaleStr=null;
  mCurrentSubtype=null;
  mAllEnabledSubtypesOfCurrentInputMethod=null;
  mVoiceInputWrapper=null;
  final NetworkInfo info=mConnectivityManager.getActiveNetworkInfo();
  mIsNetworkConnected=(info != null && info.isConnected());
}
 

Example 73

From project Juggernaut_SystemUI, under directory /src/com/android/systemui/statusbar/policy/.

Source file: StatusBarPolicy.java

  17 
vote

private void updateConnectivity(Intent intent){
  NetworkInfo info=(NetworkInfo)(intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO));
  int connectionStatus=intent.getIntExtra(ConnectivityManager.EXTRA_INET_CONDITION,0);
  int inetCondition=(connectionStatus > INET_CONDITION_THRESHOLD ? 1 : 0);
switch (info.getType()) {
case ConnectivityManager.TYPE_MOBILE:
    mInetCondition=inetCondition;
  updateDataNetType(info.getSubtype());
updateDataIcon();
updateSignalStrength();
break;
case ConnectivityManager.TYPE_WIFI:
mInetCondition=inetCondition;
if (info.isConnected()) {
mIsWifiConnected=true;
int iconId;
if (mLastWifiSignalLevel == -1) {
iconId=sWifiSignalImages[mInetCondition][0];
}
 else {
iconId=sWifiSignalImages[mInetCondition][mLastWifiSignalLevel];
}
mService.setIcon("wifi",iconId,0);
mService.setIconVisibility("wifi",true);
}
 else {
mLastWifiSignalLevel=-1;
mIsWifiConnected=false;
int iconId=sWifiSignalImages[0][0];
mService.setIcon("wifi",iconId,0);
mService.setIconVisibility("wifi",false);
}
updateSignalStrength();
break;
case ConnectivityManager.TYPE_WIMAX:
mInetCondition=inetCondition;
updateWiMAX(intent);
break;
}
}
 

Example 74

From project MIT-Mobile-for-Android, under directory /src/edu/mit/mitmobile2/.

Source file: ConnectionWrapper.java

  17 
vote

public boolean openURL(final String url,final ConnectionInterface callback){
  Log.d(TAG,"starting request: " + url);
  if (mConnectivityManager != null) {
    NetworkInfo networkInfo=mConnectivityManager.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isAvailable()) {
      callback.onError(ErrorType.Network);
      return false;
    }
  }
  if (Looper.myLooper() != null) {
    asynchronous(url,new Handler(){
      @Override public void handleMessage(      Message msg){
        Log.d(TAG,"openURL - asynchronous");
        if (msg.arg1 == CONNECTION_ERROR) {
          Log.d(TAG,"CONNECTION ERROR");
          callback.onError((ErrorType)msg.obj);
        }
 else         if (msg.arg1 == CONNECTION_RESPONSE) {
          Log.d(TAG,"ON RESPONSE");
          Log.d(TAG,"msg = " + msg.obj.getClass());
          InputStream i=(InputStream)msg.obj;
          callback.onResponse((InputStream)msg.obj);
        }
      }
    }
);
  }
 else {
    synchronous(url,callback);
    Log.d(TAG,"openURL - synchronous");
  }
  return true;
}
 

Example 75

From project mobilis, under directory /MXA/src/de/tudresden/inf/rn/mobilis/mxa/.

Source file: NetworkMonitor.java

  17 
vote

@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 76

From project nuxeo-android, under directory /nuxeo-android-connector/src/main/java/org/nuxeo/android/network/.

Source file: NetworkStatusBroadCastReceiver.java

  17 
vote

@Override public void onReceive(Context ctx,Intent intent){
  if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
    Bundle bundle=intent.getExtras();
    if (bundle.getBoolean(ConnectivityManager.EXTRA_NO_CONNECTIVITY)) {
      networkStatus.setNetworkReachable(false);
    }
 else {
      String reason=bundle.getString(ConnectivityManager.EXTRA_REASON);
      boolean isFailover=bundle.getBoolean(ConnectivityManager.EXTRA_IS_FAILOVER,false);
      NetworkInfo currentNetworkInfo=(NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
      NetworkInfo otherNetworkInfo=(NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);
      boolean connectivityOk=isNetworkUsable(currentNetworkInfo);
      if (!connectivityOk && otherNetworkInfo != null) {
        connectivityOk=isNetworkUsable(otherNetworkInfo);
      }
      if (!connectivityOk) {
        networkStatus.setNetworkReachable(false);
      }
 else {
        networkStatus.setNetworkReachable(true);
        networkStatus.testNuxeoServerReachable();
      }
    }
  }
}
 

Example 77

From project OAK, under directory /oak-library/src/main/java/oak/external/com/github/droidfu/http/.

Source file: BetterHttp.java

  17 
vote

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 78

From project packages_apps_BlackICEControl, under directory /src/com/blackice/control/util/.

Source file: Helpers.java

  17 
vote

/** 
 * 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 79

From project packages_apps_ROMControl, under directory /src/com/aokp/romcontrol/util/.

Source file: Helpers.java

  17 
vote

/** 
 * 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 80

From project platform_frameworks_support, under directory /v4/gingerbread/android/support/v4/net/.

Source file: ConnectivityManagerCompatGingerbread.java

  17 
vote

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 81

From project platform_packages_apps_browser, under directory /src/com/android/browser/.

Source file: BrowserSettings.java

  17 
vote

public void updateConnectionType(){
  ConnectivityManager cm=(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
  String linkPrefetchPreference=getLinkPrefetchEnabled();
  boolean linkPrefetchAllowed=linkPrefetchPreference.equals(getLinkPrefetchAlwaysPreferenceString(mContext));
  NetworkInfo ni=cm.getActiveNetworkInfo();
  if (ni != null) {
switch (ni.getType()) {
case ConnectivityManager.TYPE_WIFI:
case ConnectivityManager.TYPE_ETHERNET:
case ConnectivityManager.TYPE_BLUETOOTH:
      linkPrefetchAllowed|=linkPrefetchPreference.equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
    break;
case ConnectivityManager.TYPE_MOBILE:
case ConnectivityManager.TYPE_MOBILE_DUN:
case ConnectivityManager.TYPE_MOBILE_MMS:
case ConnectivityManager.TYPE_MOBILE_SUPL:
case ConnectivityManager.TYPE_WIMAX:
default :
  break;
}
}
if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
mLinkPrefetchAllowed=linkPrefetchAllowed;
syncManagedSettings();
}
}
 

Example 82

From project platform_packages_apps_im, under directory /src/com/android/im/service/.

Source file: RemoteImService.java

  17 
vote

private Map<String,String> loadProviderSettings(long providerId){
  ContentResolver cr=getContentResolver();
  Map<String,String> settings=Imps.ProviderSettings.queryProviderSettings(cr,providerId);
  NetworkInfo networkInfo=mNetworkConnectivityListener.getNetworkInfo();
  if ("1".equals(SystemProperties.get("ro.kernel.qemu"))) {
    settings.put(ImpsConfigNames.MSISDN,"15555218135");
  }
 else   if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
    if (!TextUtils.isEmpty(settings.get(ImpsConfigNames.SMS_ADDR))) {
      settings.put(ImpsConfigNames.SMS_AUTH,"true");
      settings.put(ImpsConfigNames.SECURE_LOGIN,"false");
    }
 else {
      String msisdn=TelephonyManager.getDefault().getLine1Number();
      if (TextUtils.isEmpty(msisdn)) {
        Log.w(TAG,"Can not read MSISDN from SIM, use a fake one." + " SMS related feature won't work.");
        msisdn="15555218135";
      }
      settings.put(ImpsConfigNames.MSISDN,msisdn);
    }
  }
  return settings;
}
 

Example 83

From project platform_packages_apps_mms, under directory /src/com/android/mms/transaction/.

Source file: TransactionService.java

  17 
vote

@Override public void onReceive(Context context,Intent intent){
  String action=intent.getAction();
  if (Log.isLoggable(LogTag.TRANSACTION,Log.VERBOSE)) {
    Log.w(TAG,"ConnectivityBroadcastReceiver.onReceive() action: " + action);
  }
  if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
    return;
  }
  boolean noConnectivity=intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false);
  NetworkInfo networkInfo=(NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
  if (Log.isLoggable(LogTag.TRANSACTION,Log.VERBOSE)) {
    Log.v(TAG,"Handle ConnectivityBroadcastReceiver.onReceive(): " + networkInfo);
  }
  if ((networkInfo == null) || (networkInfo.getType() != ConnectivityManager.TYPE_MOBILE_MMS)) {
    if (Log.isLoggable(LogTag.TRANSACTION,Log.VERBOSE)) {
      Log.v(TAG,"   type is not TYPE_MOBILE_MMS, bail");
    }
    if (networkInfo != null && Phone.REASON_VOICE_CALL_ENDED.equals(networkInfo.getReason())) {
      if (Log.isLoggable(LogTag.TRANSACTION,Log.VERBOSE)) {
        Log.v(TAG,"   reason is " + Phone.REASON_VOICE_CALL_ENDED + ", retrying mms connectivity");
      }
      renewMmsConnectivity();
    }
    return;
  }
  if (!networkInfo.isConnected()) {
    if (Log.isLoggable(LogTag.TRANSACTION,Log.VERBOSE)) {
      Log.v(TAG,"   TYPE_MOBILE_MMS not connected, bail");
    }
    return;
  }
  TransactionSettings settings=new TransactionSettings(TransactionService.this,networkInfo.getExtraInfo());
  if (TextUtils.isEmpty(settings.getMmscUrl())) {
    Log.v(TAG,"   empty MMSC url, bail");
    return;
  }
  renewMmsConnectivity();
  mServiceHandler.processPendingTransaction(null,settings);
}
 

Example 84

From project proxydroid, under directory /src/org/proxydroid/.

Source file: ConnectivityBroadcastReceiver.java

  17 
vote

public String onlineSSID(Context context,String ssid){
  String ssids[]=ListPreferenceMultiSelect.parseStoredValue(ssid);
  if (ssids == null)   return null;
  if (ssids.length < 1)   return null;
  ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo networkInfo=manager.getActiveNetworkInfo();
  if (networkInfo == null)   return null;
  if (networkInfo.getType() != ConnectivityManager.TYPE_WIFI) {
    for (    String item : ssids) {
      if (item.equals(Constraints.WIFI_AND_3G))       return item;
      if (item.equals(Constraints.ONLY_3G))       return item;
    }
    return null;
  }
  WifiManager wm=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
  WifiInfo wInfo=wm.getConnectionInfo();
  if (wInfo == null)   return null;
  String current=wInfo.getSSID();
  if (current == null || current.equals(""))   return null;
  for (  String item : ssids) {
    if (item.equals(Constraints.WIFI_AND_3G))     return item;
    if (item.equals(Constraints.ONLY_WIFI))     return item;
    if (item.equals(current))     return item;
  }
  return null;
}
 

Example 85

From project sls, under directory /src/com/adam/aslfms/util/.

Source file: Util.java

  17 
vote

public static NetworkStatus checkForOkNetwork(Context ctx){
  AppSettings settings=new AppSettings(ctx);
  PowerOptions pow=checkPower(ctx);
  NetworkOptions no=settings.getNetworkOptions(pow);
  boolean roaming=settings.getSubmitOnRoaming(pow);
  ConnectivityManager cMgr=(ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo netInfo=cMgr.getActiveNetworkInfo();
  if (netInfo == null)   return NetworkStatus.DISCONNECTED;
  if (!netInfo.isConnected())   return NetworkStatus.DISCONNECTED;
  if (netInfo.isRoaming() && !roaming)   return NetworkStatus.UNFIT;
  int netType=netInfo.getType();
  int netSubType=netInfo.getSubtype();
  if (no.isNetworkTypeForbidden(netType))   return NetworkStatus.UNFIT;
  if (no.isNetworkSubTypeForbidden(netType,netSubType))   return NetworkStatus.UNFIT;
  return NetworkStatus.OK;
}
 

Example 86

From project sms-backup-plus, under directory /src/com/zegoggles/smssync/.

Source file: ServiceBase.java

  17 
vote

/** 
 * Acquire locks
 * @param background if service is running in background (no UI)
 * @throws com.zegoggles.smssync.ServiceBase.ConnectivityErrorException when unable to connect
 */
protected void acquireLocks(boolean background) throws ConnectivityErrorException {
  if (sWakeLock == null) {
    PowerManager pMgr=(PowerManager)getSystemService(POWER_SERVICE);
    sWakeLock=pMgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,TAG);
  }
  sWakeLock.acquire();
  WifiManager wMgr=(WifiManager)getSystemService(WIFI_SERVICE);
  if (wMgr.isWifiEnabled() && getConnectivityManager().getNetworkInfo(ConnectivityManager.TYPE_WIFI) != null && getConnectivityManager().getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
    if (sWifiLock == null) {
      sWifiLock=wMgr.createWifiLock(TAG);
    }
    sWifiLock.acquire();
  }
 else   if (background && PrefStore.isWifiOnly(this)) {
    throw new ConnectivityErrorException(getString(R.string.error_wifi_only_no_connection));
  }
  NetworkInfo active=getConnectivityManager().getActiveNetworkInfo();
  if (active == null || !active.isConnectedOrConnecting()) {
    throw new ConnectivityErrorException(getString(R.string.error_no_connection));
  }
}
 

Example 87

From project SWE12-Drone, under directory /catroid/src/at/tugraz/ist/catroid/plugin/Drone/other/.

Source file: DroneWifiConnectionActivity.java

  17 
vote

@Override public synchronized void onReceive(Context context,Intent intent){
  if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
    if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,10) == WifiManager.WIFI_STATE_ENABLED) {
      Log.d(DroneConsts.DroneLogTag,"WIFI_STATE_CHANGED_ACTION -> WIFI_STATE_ENABLED");
      unregisterReceiver(wifiStateChangedReceiver);
      IntentFilter intentFilter=new IntentFilter();
      intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
      registerReceiver(wifiStateChangedReceiver,intentFilter);
      changeStatus(DroneConsts.SCANNING);
    }
  }
  if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) && wifiManager.isWifiEnabled()) {
    Log.d(DroneConsts.DroneLogTag,"SCAN_RESULTS_AVAILABLE_ACTION");
    scanned=true;
    unregisterReceiver(wifiStateChangedReceiver);
    IntentFilter intentFilter=new IntentFilter();
    intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    registerReceiver(wifiStateChangedReceiver,intentFilter);
    if (foundDrone()) {
      changeStatus(DroneConsts.CONNECTING_TO_DRONE_WIFI);
    }
 else {
      changeStatus(DroneConsts.ERROR_FINDING_DRONE);
      return;
    }
  }
  if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) && wifiManager.isWifiEnabled()) {
    NetworkInfo info=intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    Log.d(DroneConsts.DroneLogTag,"SUPPLICANT_CONNECTION_CHANGE_ACTION " + info.isConnected() + " "+ wifiManager.getConnectionInfo().getSSID());
    if (info.isConnected()) {
      if (checkConnectionToDrone()) {
        changeStatus(DroneConsts.CHECKING_FIRMWARE);
      }
 else       if (errorCount++ > 3) {
        changeStatus(DroneConsts.ERROR_CONNECTING_DRONE);
        return;
      }
    }
  }
}
 

Example 88

From project Twook, under directory /src/com/nookdevs/twook/activities/.

Source file: TimelineActivity.java

  17 
vote

/** 
 * Warns the user to start the wireless or the mobile connection  if they are not started and stops the applications.
 */
private void checkWireless(){
  ConnectivityManager cmgr=(ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
  NetworkInfo wifiInfo=cmgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
  NetworkInfo mobileInfo=cmgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
  boolean wifiConnection=(wifiInfo == null) ? false : wifiInfo.isConnected();
  boolean mobileConnection=(mobileInfo == null) ? false : mobileInfo.isConnected();
  if (!wifiConnection && !mobileConnection) {
    AlertDialog.Builder builder=new AlertDialog.Builder(this);
    builder.setTitle("Unable to start Twook.").setMessage("To use Twook an Internet connection is needed. Please enable the mobile connection" + " or the wireless connection and then restart the application.").setCancelable(false).setNeutralButton("Exit Twook",new DialogInterface.OnClickListener(){
      public void onClick(      DialogInterface dialog,      int id){
        TimelineActivity.this.finish();
      }
    }
);
    AlertDialog alertStartWifi=builder.create();
    alertStartWifi.show();
  }
}
 

Example 89

From project zaduiReader, under directory /src/cn/zadui/reader/service/.

Source file: NetworkChangedReceiver.java

  17 
vote

@Override public void onReceive(Context context,Intent intent){
  ConnectivityManager connectivityManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo activeNetInfo=connectivityManager.getActiveNetworkInfo();
  if (activeNetInfo != null && activeNetInfo.getState() == NetworkInfo.State.CONNECTED) {
    if (activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
      Log.d(TAG,"wifi connected!");
      startDownloadService(context);
    }
 else     if (activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE && !Settings.getBooleanPreferenceValue(context,Settings.PRE_WIFI_ONLY,Settings.DEF_WIFI_ONLY)) {
      Log.d(TAG,"Mobile Network connected!");
      startDownloadService(context);
    }
 else {
    }
  }
}
 

Example 90

From project android_frameworks_ex, under directory /common/java/com/android/common/.

Source file: NetworkConnectivityListener.java

  15 
vote

@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 91

From project android_packages_apps_QuickSearchBox, under directory /src/com/android/quicksearchbox/google/.

Source file: GoogleSuggestClient.java

  15 
vote

private NetworkInfo getActiveNetworkInfo(){
  ConnectivityManager connectivity=(ConnectivityManager)getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
  if (connectivity == null) {
    return null;
  }
  return connectivity.getActiveNetworkInfo();
}
 

Example 92

From project beintoo-android-sdk, under directory /BeintooSDK/src/com/beintoo/beintoosdk/.

Source file: BeintooConnection.java

  15 
vote

/** 
 * 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 93

From project Book-Catalogue, under directory /src/com/eleybourn/bookcatalogue/.

Source file: Utils.java

  15 
vote

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 94

From project danbo, under directory /src/us/donmai/danbooru/danbo/util/.

Source file: NetworkState.java

  15 
vote

/** 
 * @return Returns true if a connection is available for passing data
 */
public boolean connectionAvailable(){
  boolean networkAvailable=false;
  NetworkInfo[] networks=cm.getAllNetworkInfo();
  for (int i=0; i < networks.length; i++) {
    if (networks[i].isConnected()) {
      networkAvailable=true;
    }
 else {
      continue;
    }
  }
  return networkAvailable;
}
 

Example 95

From project DigitbooksExamples, under directory /DigitbooksExamples/src/fr/digitbooks/android/examples/util/.

Source file: Helpers.java

  15 
vote

/** 
 * 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 96

From project FlipDroid, under directory /app/src/com/goal98/flipdroid2/util/.

Source file: NetworkUtil.java

  15 
vote

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 97

From project huiswerk, under directory /print/zxing-1.6/android/src/com/google/zxing/client/android/wifi/.

Source file: WifiReceiver.java

  15 
vote

@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 98

From project PartyWare, under directory /android/src/com/google/zxing/client/android/wifi/.

Source file: WifiReceiver.java

  15 
vote

@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 99

From project platform_frameworks_ex, under directory /common/java/com/android/common/.

Source file: NetworkConnectivityListener.java

  15 
vote

@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 100

From project Playlist, under directory /src/com/google/zxing/client/android/wifi/.

Source file: WifiReceiver.java

  15 
vote

@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 101

From project SASAbus, under directory /src/it/sasabz/android/sasabus/classes/.

Source file: FileRetriever.java

  15 
vote

/** 
 * this method checks if a networkconnection is active or not
 * @return boolean if the network is reachable or not
 */
private boolean haveNetworkConnection(){
  boolean haveConnectedWifi=false;
  boolean haveConnectedMobile=false;
  ConnectivityManager cm=(ConnectivityManager)(activity.getSystemService(Context.CONNECTIVITY_SERVICE));
  NetworkInfo[] netInfo=cm.getAllNetworkInfo();
  for (  NetworkInfo ni : netInfo) {
    if (ni.getTypeName().equalsIgnoreCase("WIFI"))     if (ni.isConnected())     haveConnectedWifi=true;
    if (ni.getTypeName().equalsIgnoreCase("MOBILE"))     if (ni.isConnected())     haveConnectedMobile=true;
  }
  return haveConnectedWifi || haveConnectedMobile;
}
 

Example 102

From project SMSSync, under directory /smssync/src/org/addhen/smssync/widget/.

Source file: SmsSyncAppWidgetProvider.java

  15 
vote

@Override public void onStart(final Intent intent,final int startId){
  final Runnable updateUI=new Runnable(){
    public void run(){
      String action=intent.getAction();
      if (INTENT_PREV.equals(action) || INTENT_NEXT.equals(action)) {
        buildUpdate(intent,startId);
      }
 else {
        if (INTENT_REFRESH.equals(action)) {
          pendingMsgIndex=0;
        }
        pendingMsgs=showMessages();
        buildUpdate(intent,startId);
      }
    }
  }
;
  ConnectivityManager cm=(ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
  if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()) {
    new Thread(updateUI).start();
  }
 else {
    BroadcastReceiver networkChange=new BroadcastReceiver(){
      @Override public void onReceive(      Context context,      Intent intent){
        try {
          NetworkInfo ni=intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
          if (ni != null && ni.isConnected()) {
            new Thread(updateUI).start();
            SmsSyncAppWidgetService.this.unregisterReceiver(this);
          }
        }
 catch (        Exception e) {
          Log.e(CLASS_TAG,"receiver error",e);
        }
      }
    }
;
    registerReceiver(networkChange,new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
  }
}
 

Example 103

From project SWADroid, under directory /SWADroid/src/es/ugr/swad/swadroid/modules/.

Source file: Module.java

  15 
vote

/** 
 * Checks if any connection is available 
 * @param ctx Application context
 * @return true if there is a connection available, false in other case
 */
public static boolean connectionAvailable(Context ctx){
  boolean connAvailable=false;
  ConnectivityManager connec=(ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo[] networks=connec.getAllNetworkInfo();
  for (int i=0; i < 2; i++) {
    if (networks[i].isConnected()) {
      connAvailable=true;
    }
  }
  return connAvailable;
}
 

Example 104

From project titanium_modules, under directory /beintoosdk/mobile/android/src/com/beintoo/beintoosdk/.

Source file: BeintooConnection.java

  15 
vote

/** 
 * 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 105

From project zxing-android, under directory /src/com/laundrylocker/barcodescanner/wifi/.

Source file: WifiReceiver.java

  15 
vote

@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 Disconnected for ssid: " + ssid);
          parent.gotError();
        }
      }
    }
  }
}
 

Example 106

From project zxing-iphone, under directory /android/src/com/google/zxing/client/android/wifi/.

Source file: WifiReceiver.java

  15 
vote

@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();
        }
      }
    }
  }
}