List of usage examples for android.net ConnectivityManager setProcessDefaultNetwork
@Deprecated public static boolean setProcessDefaultNetwork(@Nullable Network network)
From source file:org.universAAL.android.services.MiddlewareService.java
/** * Helper method to determine if there is a WiFi data connection. * //from ww w .ja v a 2 s.c om * @return True if there is one. */ // private boolean isWifiOn(){ // try { // Thread.sleep(3000); // } catch (InterruptedException e) { // e.printStackTrace(); // } // ConnectivityManager connectivityManager = (ConnectivityManager) MiddlewareService.this // .getSystemService(Context.CONNECTIVITY_SERVICE); // NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo(); // return (netInfo != null && netInfo.getType() == ConnectivityManager.TYPE_WIFI); // } @SuppressLint("NewApi") private void requestLollipopWifi() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ConnectivityManager connectivityManager = (ConnectivityManager) MiddlewareService.this .getSystemService(Context.CONNECTIVITY_SERVICE); connectivityManager.requestNetwork( new NetworkRequest.Builder().addTransportType(NetworkCapabilities.TRANSPORT_WIFI).build(), new ConnectivityManager.NetworkCallback() { public void onAvailable(Network network) { Log.d(TAG, "Setting process default network " + network.toString()); ConnectivityManager.setProcessDefaultNetwork(network); } }); } }