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:net.freifunk.android.discover.Main.java
void updateMaps() { final String URL = "https://raw.githubusercontent.com/NiJen/AndroidFreifunkNord/master/MapUrls.json"; SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); final ConnectivityManager connManager = (ConnectivityManager) getSystemService( this.getBaseContext().CONNECTIVITY_SERVICE); final NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); MapMaster mapMaster = MapMaster.getInstance(); final DatabaseHelper databaseHelper = DatabaseHelper.getInstance(this.getApplicationContext()); final RequestQueueHelper requestHelper = RequestQueueHelper.getInstance(this.getApplicationContext()); final HashMap<String, NodeMap> mapList = databaseHelper.getAllNodeMaps(); final boolean sync_wifi = sharedPrefs.getBoolean("sync_wifi", true); final int sync_frequency = Integer.parseInt(sharedPrefs.getString("sync_frequency", "0")); if (sync_wifi == true) { Log.d(TAG, "Performing online update ONLY via wifi, every " + sync_frequency + " minutes"); } else {/*from w ww.j ava 2 s . co m*/ Log.d(TAG, "Performing online update ALWAYS, every " + sync_frequency + " minutes"); } updateTask = new TimerTask() { @Override public void run() { /* load from database */ for (NodeMap map : mapList.values()) { map.loadNodes(); } /* load from web */ if (connManager.getActiveNetworkInfo() != null && (sync_wifi == false || mWifi.isConnected() == true)) { Log.d(TAG, "Performing online update. Next update at " + scheduledExecutionTime()); requestHelper.add(new JsonObjectRequest(URL, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { try { MapMaster mapMaster = MapMaster.getInstance(); Iterator mapkeys = jsonObject.keys(); while (mapkeys.hasNext()) { String mapName = mapkeys.next().toString(); String mapUrl = jsonObject.getString(mapName); NodeMap m = new NodeMap(mapName, mapUrl); databaseHelper.addNodeMap(m); // only update, if not already found in database if (!mapList.containsKey(m.getMapName())) { m.loadNodes(); } } } catch (JSONException e) { Log.e(TAG, e.toString()); } finally { requestHelper.RequestDone(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { Log.e(TAG, volleyError.toString()); requestHelper.RequestDone(); } })); } else { Log.d(TAG, "Online update is skipped. Next try at " + scheduledExecutionTime()); } } }; Timer timer = new Timer(); if (sync_frequency > 0) { timer.schedule(updateTask, 0, (sync_frequency * 60 * 1000)); } else { timer.schedule(updateTask, 0); } }
From source file:cn.bidaround.ytcore.kaixin.KaixinUtil.java
/** * Httpapn??????/* www .j a v a2s . com*/ * * @throws IOException */ @SuppressWarnings("deprecation") public static HttpURLConnection getConnection(Context context, URL url) throws IOException { // ?WIFI?WIFI?? HttpsURLConnection httpsURLConn = null; // ???? ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connMgr.getActiveNetworkInfo(); // ?WIFI if (null != netInfo && ConnectivityManager.TYPE_WIFI == netInfo.getType()) { httpsURLConn = (HttpsURLConnection) url.openConnection(); } else {// ?WIFI? String proxyHost = android.net.Proxy.getDefaultHost(); if (null == proxyHost) { // ? httpsURLConn = (HttpsURLConnection) url.openConnection(); } else { // ?? java.net.Proxy p = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress( android.net.Proxy.getDefaultHost(), android.net.Proxy.getDefaultPort())); httpsURLConn = (HttpsURLConnection) url.openConnection(p); } } return httpsURLConn; }
From source file:com.ds.kaixin.Util.java
/** * Httpapn//from w w w . ja v a2 s. c o m * * @throws IOException */ public static HttpURLConnection getConnection(Context context, URL url) throws IOException { // WIFIWIFI HttpsURLConnection httpsURLConn = null; // ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connMgr.getActiveNetworkInfo(); // WIFI if (null != netInfo && ConnectivityManager.TYPE_WIFI == netInfo.getType()) { httpsURLConn = (HttpsURLConnection) url.openConnection(); } else {// WIFI String proxyHost = android.net.Proxy.getDefaultHost(); if (null == proxyHost) { // httpsURLConn = (HttpsURLConnection) url.openConnection(); } else { // java.net.Proxy p = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress( android.net.Proxy.getDefaultHost(), android.net.Proxy.getDefaultPort())); httpsURLConn = (HttpsURLConnection) url.openConnection(p); } } return httpsURLConn; }
From source file:org.fdroid.fdroid.UpdateService.java
/** * If we are to update the repos only on wifi, make sure that connection is active *//* w w w. ja v a 2 s. c o m*/ private static boolean isNetworkAvailableForUpdate(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); // this could be cellular or wifi NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork == null) { return false; } if (activeNetwork.getType() != ConnectivityManager.TYPE_WIFI && Preferences.get().isUpdateOnlyOnWifi()) { Log.i(TAG, "Skipping update - wifi not available"); return false; } return activeNetwork.isConnectedOrConnecting(); }
From source file:com.jtechme.apphub.UpdateService.java
/** * If we are to update the repos only on wifi, make sure that connection is active *///from www . j a v a 2 s.com public static boolean isNetworkAvailableForUpdate(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); // this could be cellular or wifi NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork == null) return false; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (activeNetwork.getType() != ConnectivityManager.TYPE_WIFI && prefs.getBoolean(Preferences.PREF_UPD_WIFI_ONLY, false)) { Log.i(TAG, "Skipping update - wifi not available"); return false; } return activeNetwork.isConnectedOrConnecting(); }
From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java
public static int getMaxBitrate(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getActiveNetworkInfo(); if (networkInfo == null) { return 0; }//from ww w . j a v a2 s . c o m 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")); }
From source file:org.cirdles.chroni.ImportFilesActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handles menu item selection switch (item.getItemId()) { case R.id.exitMenu: finish();/*from w w w. j a va 2s . c om*/ return true; case R.id.helpMenu: // Takes user to help blog // Checks internet connection before downloading files ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); NetworkInfo mobileWifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (mobileWifi.isConnected()) { Intent openHelpBlog = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.chroni_help_address))); startActivity(openHelpBlog); } else { new AlertDialog.Builder(this) .setMessage("You are not connected to WiFi, mobile data rates may apply. " + "Do you wish to continue?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Intent openHelpBlog = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.chroni_help_address))); startActivity(openHelpBlog); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).show(); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:cx.ring.service.LocalService.java
@Override public void onCreate() { Log.e(TAG, "onCreate"); super.onCreate(); mediaManager = new MediaManager(this); notificationManager = NotificationManagerCompat.from(this); final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); final int cacheSize = maxMemory / 8; mMemoryCache = new LruCache<Long, Bitmap>(cacheSize) { @Override//from w ww . j a v a2 s. c o m protected int sizeOf(Long key, Bitmap bitmap) { return bitmap.getByteCount() / 1024; } }; historyManager = new HistoryManager(this); Intent intent = new Intent(this, DRingService.class); startService(intent); bindService(intent, mConnection, BIND_AUTO_CREATE | BIND_IMPORTANT | BIND_ABOVE_CLIENT); ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); isWifiConn = ni != null && ni.isConnected(); ni = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); isMobileConn = ni != null && ni.isConnected(); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); canUseContacts = sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_CONTACTS, true); canUseMobile = sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_MOBILE, true); sharedPreferences.registerOnSharedPreferenceChangeListener(this); }
From source file:org.sufficientlysecure.keychain.ui.transfer.presenter.TransferPresenter.java
private boolean isWifiConnected() { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); return wifiNetwork.isConnected(); }
From source file:github.daneren2005.dsub.util.Util.java
public static int getPreloadCount(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getActiveNetworkInfo(); if (networkInfo == null) { return 3; }/* w ww . j ava 2 s . c o m*/ SharedPreferences prefs = getPreferences(context); boolean wifi = networkInfo.getType() == ConnectivityManager.TYPE_WIFI; int preloadCount = Integer.parseInt(prefs.getString(wifi ? Constants.PREFERENCES_KEY_PRELOAD_COUNT_WIFI : Constants.PREFERENCES_KEY_PRELOAD_COUNT_MOBILE, "-1")); return preloadCount == -1 ? Integer.MAX_VALUE : preloadCount; }