Example usage for android.net Network toString

List of usage examples for android.net Network toString

Introduction

In this page you can find the example usage for android.net Network toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:org.universAAL.android.services.MiddlewareService.java

/**
 * Helper method to determine if there is a WiFi data connection.
 * // w  w w. j a v  a2  s.co m
 * @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);
                    }
                });
    }
}