當前位置: 首頁>>代碼示例>>Java>>正文


Java WifiManager.getConnectionInfo方法代碼示例

本文整理匯總了Java中android.net.wifi.WifiManager.getConnectionInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java WifiManager.getConnectionInfo方法的具體用法?Java WifiManager.getConnectionInfo怎麽用?Java WifiManager.getConnectionInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.net.wifi.WifiManager的用法示例。


在下文中一共展示了WifiManager.getConnectionInfo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkWifiLinked

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * 檢查是否在同一wifi,如果三分鍾內連接到同一wifi提示連接成功
 */
protected void checkWifiLinked(TvBoxInfo tvBoxInfo) {
    String ssid = tvBoxInfo.getSsid();
    String localSSid = WifiUtil.getWifiName(this);
    if(!TextUtils.isEmpty(ssid)) {
        LogUtils.d(ConstantValues.LOG_CHECKWIFI_PREFIX+" 當前wifi"+localSSid+",需要連接wifi"+ssid);
        WifiManager wifiManger = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManger.getConnectionInfo();
        String localIp = intToIp(wifiInfo.getIpAddress());
        String ipStr = tvBoxInfo.getBox_ip();
        if(ssid.endsWith(localSSid)&&!TextUtils.isEmpty(localSSid)&&!localIp.substring(0,localIp.lastIndexOf(".")).equals(ipStr.substring(0, ipStr.lastIndexOf(".")))) {
            LogUtils.d(ConstantValues.LOG_CHECKWIFI_PREFIX+" 連接到指定wifi,綁定成功取消檢測");
            mSession.setWifiSsid(ssid);
            mSession.setTvBoxUrl(tvBoxInfo);
            initBindcodeResult();
            mHandler.removeMessages(CANCEL_CHECK_WIFI);
            mHandler.sendEmptyMessage(CANCEL_CHECK_WIFI);
        }else {
            LogUtils.d(ConstantValues.LOG_CHECKWIFI_PREFIX+" 當前未連接wifi,繼續檢測...");
            startCheckWifiLinkedTimer();
        }
    }else {
        // 每隔一秒檢測是否已連接同一wifi
        startCheckWifiLinkedTimer();
    }
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:29,代碼來源:BaseActivity.java

示例2: getDeviceIpAddress

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
private InetAddress getDeviceIpAddress(WifiManager wifi) {
	InetAddress result = null;
	try {
		// default to Android localhost
		result = InetAddress.getByName("10.0.0.2");

		// figure out our wifi address, otherwise bail
		WifiInfo wifiinfo = wifi.getConnectionInfo();
		int intaddr = wifiinfo.getIpAddress();
		byte[] byteaddr = new byte[] { (byte) (intaddr & 0xff), (byte) (intaddr >> 8 & 0xff), (byte) (intaddr >> 16 & 0xff), (byte) (intaddr >> 24 & 0xff) };
		result = InetAddress.getByAddress(byteaddr);
	} catch (UnknownHostException e) {
		e.printStackTrace();
		Log.e(TAG, "getDeviceIpAddress Error: " + e.getMessage());
	}

	return result;
}
 
開發者ID:hoanglm4,項目名稱:RxAndroidTBP,代碼行數:19,代碼來源:MDnsHelper.java

示例3: getSSID

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public String getSSID() {
    WifiManager wifiManager = (WifiManager) getSystemService("wifi");
    if (wifiManager == null) {
        return null;
    }
    WifiInfo connectionInfo = wifiManager.getConnectionInfo();
    if (connectionInfo == null) {
        return null;
    }
    String ssid = connectionInfo.getSSID();
    if (ssid == null) {
        ssid = null;
    }
    return ssid;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:16,代碼來源:DeviceHelper.java

示例4: getWifiAddress

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static String getWifiAddress(Context context) {
    WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);
    if(wifiMgr == null){
        return null;
    }
    WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
    int ip = wifiInfo.getIpAddress();
    return Formatter.formatIpAddress(ip);
}
 
開發者ID:hyb1996,項目名稱:Auto.js,代碼行數:10,代碼來源:WifiTool.java

示例5: getLocalIpAddress

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * 獲取本地Ip地址
 *
 * @param context
 * @return
 */
public static String getLocalIpAddress(Context context) {
    try {
        WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = wifi.getConnectionInfo();
        int ipAddress = info.getIpAddress();
        String Ipv4Address = InetAddress
                .getByName(
                        String.format("%d.%d.%d.%d", (ipAddress & 0xff),
                                (ipAddress >> 8 & 0xff),
                                (ipAddress >> 16 & 0xff),
                                (ipAddress >> 24 & 0xff))).getHostAddress()
                .toString();
        return Ipv4Address;
    } catch (Exception e) {
        e.printStackTrace();
        JLog.e(e.toString());
    }
    return null;
}
 
開發者ID:jeasinlee,項目名稱:AndroidBasicLibs,代碼行數:26,代碼來源:AndroidUtil.java

示例6: a

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static String a() {
    try {
        Context context = Global.getContext();
        if (context == null) {
            return "";
        }
        WifiManager wifiManager = (WifiManager) context.getSystemService("wifi");
        if (wifiManager == null) {
            return "";
        }
        WifiInfo connectionInfo = wifiManager.getConnectionInfo();
        if (connectionInfo == null) {
            return "";
        }
        return connectionInfo.getMacAddress();
    } catch (Throwable e) {
        f.b("MobileInfoUtil", "getLocalMacAddress>>>", e);
        return "";
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:21,代碼來源:c.java

示例7: getConnectWifiSsid

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * 獲取連接的wifi的名稱
 * 
 * @param context
 * @return
 */
public static String getConnectWifiSsid(Context context)
{
    if (isWifiConnect(context))
    {
        WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
        if (wifiManager != null)
        {
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            if (wifiInfo != null)
            {
                return wifiInfo.getSSID();
            }
        }
    }
    
    return "";
}
 
開發者ID:zhuyu1022,項目名稱:amap,代碼行數:24,代碼來源:MIP_NetworkUtils.java

示例8: onReceive

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    WifiManager wifiManager = (WifiManager) context
            .getSystemService(context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo.getBSSID() != null) {
        // wifi信號強度
        int signalLevel = WifiManager.calculateSignalLevel(
                wifiInfo.getRssi(), 4);
        if (signalLevel == 0) {
            imgNetWorkState.setImageDrawable(context.getResources()
                    .getDrawable(R.drawable.wifi_1));
        } else if (signalLevel == 1) {
            imgNetWorkState.setImageDrawable(context.getResources()
                    .getDrawable(R.drawable.wifi_2));

        } else if (signalLevel == 2) {
            imgNetWorkState.setImageDrawable(context.getResources()
                    .getDrawable(R.drawable.wifi_3));

        } else if (signalLevel == 3) {
            imgNetWorkState.setImageDrawable(context.getResources()
                    .getDrawable(R.drawable.networkstate_on));
        }
        if (d)
            Toast.makeText(context, "wifi level" + signalLevel,
                    Toast.LENGTH_SHORT).show();
    }
}
 
開發者ID:Evan-Galvin,項目名稱:FreeStreams-TVLauncher,代碼行數:30,代碼來源:GameTitleView.java

示例9: getConnectWifiIp

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * 獲取當前連接wifi的名稱
 *
 * @return
 */
public static String getConnectWifiIp(Context context) {
    if (isWifiConnected(context)) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        int ipAddress = wifiInfo.getIpAddress();
        if (ipAddress == 0) {
            return null;
        }
        return ((ipAddress & 0xff) + "." + (ipAddress >> 8 & 0xff) + "."
                + (ipAddress >> 16 & 0xff) + "." + (ipAddress >> 24 & 0xff));
    }
    return null;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:NetworkUtils.java

示例10: getConnectWifiSsid

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * 獲取當前連接wifi的名稱
 *
 * @return
 */
public static String getConnectWifiSsid(Context context) {
    if (isWifiConnected(context)) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        return wifiInfo.getSSID();
    }
    return null;
}
 
開發者ID:zwmlibs,項目名稱:BookReader-master,代碼行數:14,代碼來源:NetworkUtils.java

示例11: getMacAddress

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * 獲取 MAC 地址
 * <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
 */
public static String getMacAddress(Context context) {
    //wifi mac地址
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    String mac = info.getMacAddress();
    JLog.i(" MAC:" + mac);
    return mac;
}
 
開發者ID:jeasinlee,項目名稱:AndroidBasicLibs,代碼行數:13,代碼來源:AndroidUtil.java

示例12: isWifiConnected

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * Checks if WiFi is enabled and connected to a network.
 * <b>Note</b>: This does not check access to the Internet.
 *
 * @param context Which context to use to check
 * @return {@code True} if WiFi is enabled and connected to a network, {@code false} otherwise
 */
@RequiresPermission(Manifest.permission.ACCESS_WIFI_STATE)
public static boolean isWifiConnected(@NonNull final Context context) {
    final WifiManager wiFiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (wiFiManager != null && wiFiManager.isWifiEnabled()) {
        // Wi-Fi adapter is ON
        final WifiInfo wifiInfo = wiFiManager.getConnectionInfo();
        return wifiInfo != null && wifiInfo.getNetworkId() != -1;
    } else {
        // Wi-Fi adapter is OFF
        return false;
    }
}
 
開發者ID:milosmns,項目名稱:silly-android,代碼行數:20,代碼來源:SillyAndroid.java

示例13: getLocalMacAddress

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
 * 獲取Mac地址
 *
 * @param activity
 * @return
 */
public static String getLocalMacAddress(Activity activity) {
    WifiManager wifi = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    String mac = info.getMacAddress();
    return mac;
}
 
開發者ID:zhou-you,項目名稱:RxEasyHttp,代碼行數:13,代碼來源:AppTools.java

示例14: getIp

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static String getIp(Context context) {
    int networkType = getNetworkType(context);
    if (networkType == ConnectivityManager.TYPE_WIFI) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        int ipAddress = wifiInfo.getIpAddress();
        return (ipAddress & 0xFF) + "." +
                ((ipAddress >> 8) & 0xFF) + "." +
                ((ipAddress >> 16) & 0xFF) + "." +
                (ipAddress >> 24 & 0xFF);
    } else {
        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) {
                        return inetAddress.getHostAddress();
                    }
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
        return null;
    }

}
 
開發者ID:zeng3234,項目名稱:GrowingProject,代碼行數:29,代碼來源:NetworkUtils.java

示例15: getIPAddress

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static String getIPAddress(Context context) {
    NetworkInfo info = ((ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
    if (info != null && info.isConnected()) {
        if (info.getType() == ConnectivityManager.TYPE_MOBILE) {//當前使用2G/3G/4G網絡
            try {
                //Enumeration<NetworkInterface> en=NetworkInterface.getNetworkInterfaces();
                for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
                    NetworkInterface intf = en.nextElement();
                    for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                        InetAddress inetAddress = enumIpAddr.nextElement();
                        if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
                            return inetAddress.getHostAddress();
                        }
                    }
                }
            } catch (SocketException e) {
                e.printStackTrace();
            }

        } else if (info.getType() == ConnectivityManager.TYPE_WIFI) {//當前使用無線網絡
            WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            String ipAddress = intIP2StringIP(wifiInfo.getIpAddress());//得到IPV4地址
            return ipAddress;
        }
    } else {
        //當前無網絡連接,請在設置中打開網絡
    }
    return null;
}
 
開發者ID:jiangkang,項目名稱:KTools,代碼行數:32,代碼來源:DeviceUtils.java


注:本文中的android.net.wifi.WifiManager.getConnectionInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。