is Wireless Direct Connection - Android android.net

Android examples for android.net:ConnectivityManager

Description

is Wireless Direct Connection

Demo Code

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;

public class Main{

    public static boolean isWirelessDirect(Context context) {
        ConnectivityManager connManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = connManager.getActiveNetworkInfo();

        if (netInfo != null && netInfo.isConnected()
                && (netInfo.getType() == ConnectivityManager.TYPE_WIFI)) {
            WifiManager wifiManager = (WifiManager) context
                    .getSystemService(Context.WIFI_SERVICE);
            DhcpInfo dhcpInfo = wifiManager.getDhcpInfo();

            if ((dhcpInfo != null) && (dhcpInfo.gateway == 0)) {
               return true;
            }//from  w  w  w  .  ja  v  a2  s  .  com
        }
        return false;
    }
    private static DhcpInfo getDhcpInfo(Context context) {
        return getWifiManager(context).getDhcpInfo();
    }
    private static WifiManager getWifiManager(Context context) {
      return (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
  }
}

Related Tutorials