List of usage examples for android.net ConnectivityManager TYPE_WIFI
int TYPE_WIFI
To view the source code for android.net ConnectivityManager TYPE_WIFI.
Click Source Link
From source file:org.gateshipone.malp.application.artworkdatabase.BulkDownloadService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null && intent.getAction() != null && intent.getAction().equals(ACTION_START_BULKDOWNLOAD)) { Log.v(TAG, "Starting bulk download in service with thread id: " + Thread.currentThread().getId()); // reset counter mRemainingArtists = 0;/* www .java2 s . c o m*/ mRemainingAlbums = 0; mSumImageDownloads = 0; String artistProvider = getString(R.string.pref_artwork_provider_artist_default); String albumProvider = getString(R.string.pref_artwork_provider_album_default); mWifiOnly = true; // read setting from extras Bundle extras = intent.getExtras(); if (extras != null) { artistProvider = extras.getString(BUNDLE_KEY_ARTIST_PROVIDER, getString(R.string.pref_artwork_provider_artist_default)); albumProvider = extras.getString(BUNDLE_KEY_ALBUM_PROVIDER, getString(R.string.pref_artwork_provider_album_default)); mWifiOnly = intent.getBooleanExtra(BUNDLE_KEY_WIFI_ONLY, true); } ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (null == netInfo) { return START_NOT_STICKY; } boolean isWifi = netInfo.getType() == ConnectivityManager.TYPE_WIFI || netInfo.getType() == ConnectivityManager.TYPE_ETHERNET; if (mWifiOnly && !isWifi) { return START_NOT_STICKY; } PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MALP_BulkDownloader"); ArtworkManager artworkManager = ArtworkManager.getInstance(getApplicationContext()); artworkManager.initialize(artistProvider, albumProvider, mWifiOnly); // FIXME do some timeout checking. e.g. 5 minutes no new image then cancel the process mWakelock.acquire(); ConnectionManager.reconnectLastServer(this); } return START_NOT_STICKY; }
From source file:piuk.blockchain.android.ui.AbstractWalletActivity.java
public final boolean isWifiEnabled() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (info.isConnected()) { return true; } else {// www . j ava 2s.c o m return false; } }
From source file:org.dvbviewer.controller.ui.fragments.ChannelPager.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);/*from w w w. ja v a2 s . co m*/ // setRetainInstance(true); mAdapter = new PagerAdapter(getChildFragmentManager(), mGroupCursor); ConnectivityManager connManager = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); mNetworkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); prefs = new DVBViewerPreferences(getActivity()); showGroups = prefs.getPrefs().getBoolean(DVBViewerPreferences.KEY_CHANNELS_SHOW_GROUPS, false); showExtraGroup = prefs.getPrefs().getBoolean(DVBViewerPreferences.KEY_CHANNELS_SHOW_ALL_AS_GROUP, false); showFavs = prefs.getPrefs().getBoolean(DVBViewerPreferences.KEY_CHANNELS_USE_FAVS, false); showNowPlaying = prefs.getPrefs().getBoolean(DVBViewerPreferences.KEY_CHANNELS_SHOW_NOW_PLAYING, true); showNowPlayingWifi = prefs.getPrefs() .getBoolean(DVBViewerPreferences.KEY_CHANNELS_SHOW_NOW_PLAYING_WIFI_ONLY, true); }
From source file:org.m2x.rssreader.service.FetcherService.java
@SuppressWarnings("deprecation") @Override//from w w w.ja va 2 s . com public void onHandleIntent(Intent intent) { if (intent == null) { return; } ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); // Connectivity issue, we quit if (networkInfo == null || networkInfo.getState() != NetworkInfo.State.CONNECTED) { broadcastNetworkProblem(); return; } boolean isFromAutoRefresh = intent.getBooleanExtra(Constants.FROM_AUTO_REFRESH, false); boolean skipFetch = isFromAutoRefresh && PrefUtils.getBoolean(PrefUtils.AUTO_REFRESH_ONLY_ON_WIFI, false) && networkInfo.getType() != ConnectivityManager.TYPE_WIFI; // We need to skip the fetching process, so we quit if (skipFetch) { return; } if (ACTION_DOWNLOAD_IMAGES.equals(intent.getAction())) { downloadAllImages(); } else { // == Constants.ACTION_REFRESH_FEEDS PrefUtils.putBoolean(PrefUtils.IS_REFRESHING, true); if (isFromAutoRefresh) { PrefUtils.putLong(PrefUtils.LAST_SCHEDULED_REFRESH, SystemClock.elapsedRealtime()); } String feedId = intent.getStringExtra(Constants.FEED_ID); int newCount = (feedId == null ? refreshFeeds() : refreshFeed(feedId)); if (newCount > 0) { if (PrefUtils.getBoolean(PrefUtils.PUSH_NOTIFICATION, true)) { Cursor cursor = getContentResolver().query(EntryColumns.CONTENT_URI, new String[] { COUNT }, EntryColumns.WHERE_UNREAD, null, null); cursor.moveToFirst(); newCount = cursor.getInt(0); // The number has possibly changed cursor.close(); if (newCount > 0) { String text = getResources().getQuantityString(R.plurals.number_of_new_entries, newCount, newCount); Intent notificationIntent = new Intent(FetcherService.this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(FetcherService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder( MainApplication.getContext()).setContentIntent(contentIntent) .setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) // .setTicker(text).setWhen(System.currentTimeMillis()).setAutoCancel(true) .setContentTitle(getString(R.string.rssreader_feeds)).setContentText(text) .setLights(0xffffffff, 300, 1000); if (PrefUtils.getBoolean(PrefUtils.NOTIFICATIONS_VIBRATE, false)) { notifBuilder.setVibrate(new long[] { 0, 1000 }); } String ringtone = PrefUtils.getString(PrefUtils.NOTIFICATIONS_RINGTONE, null); if (ringtone != null && ringtone.length() > 0) { notifBuilder.setSound(Uri.parse(ringtone)); } if (Constants.NOTIF_MGR != null) { Constants.NOTIF_MGR.notify(0, notifBuilder.getNotification()); } } } else if (Constants.NOTIF_MGR != null) { Constants.NOTIF_MGR.cancel(0); } } downloadAllImages(); PrefUtils.putBoolean(PrefUtils.IS_REFRESHING, false); broadcastRefreshFinished(); } }
From source file:org.adblockplus.android.AdblockPlus.java
/** * Checks if device has a WiFi connection available. *///from ww w. j a v a2 s .c om public static boolean isWiFiConnected(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = null; if (connectivityManager != null) { networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); } return networkInfo == null ? false : networkInfo.isConnected(); }
From source file:in.huohua.peterson.network.NetworkUtils.java
public static boolean isWifiConnected(Context context) { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); return mWifi.isConnected(); }
From source file:edu.mit.mobile.android.locast.data.CastMedia.java
/** * Attempts to guess if the video player should show a high quality version of the video or a * lower bitrate version.//from w w w .j a v a2 s . c om * * @return true if it seems as though playing high-quality would be expensive or wouldn't work */ public static boolean shouldShowLowQuality(Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(cm); final NetworkInfo net = cm.getActiveNetworkInfo(); if (metered || net == null || net.isRoaming()) { return true; } // this is because these devices tend to not be able to be powerful enough to show the full // res video if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { return true; } final int type = net.getType(); switch (type) { // generally these are fast and cheap/free case ConnectivityManager.TYPE_WIFI: case ConnectivityManager.TYPE_ETHERNET: case ConnectivityManager.TYPE_WIMAX: return false; default: return true; } }
From source file:ti.modules.titanium.network.NetworkModule.java
protected int networkTypeToTitanium(boolean online, int androidType) { int type = NetworkModule.NETWORK_UNKNOWN; if (online) { switch (androidType) { case ConnectivityManager.TYPE_WIFI: type = NetworkModule.NETWORK_WIFI; break; case ConnectivityManager.TYPE_MOBILE: type = NetworkModule.NETWORK_MOBILE; break; default:/* w w w . ja v a2s .c om*/ type = NetworkModule.NETWORK_UNKNOWN; } } else { type = NetworkModule.NETWORK_NONE; } return type; }
From source file:com.fairphone.updater.UpdaterService.java
private boolean hasInternetConnection() { ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); boolean is3g = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting(); boolean isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting(); return isWifi || is3g; }
From source file:totalcross.android.ConnectionManager4A.java
public static String getLocalHost() { try {// w w w.j a v a 2s .c o m ConnectivityManager connMgr = (ConnectivityManager) Launcher4A.loader .getSystemService(Context.CONNECTIVITY_SERVICE); int type = connMgr.getActiveNetworkInfo().getType(); if (type == ConnectivityManager.TYPE_WIFI) { WifiManager wifiMgr = (WifiManager) Launcher4A.loader.getSystemService(Context.WIFI_SERVICE); return ipAddressToString(wifiMgr.getDhcpInfo().ipAddress); } String ip = getLocalIpAddress(); return ip != null ? ip : InetAddress.getLocalHost().getHostAddress(); } catch (Exception e) { } return "127.0.0.1"; }