目前分類:程式開發 (3)

瀏覽方式: 標題列表 簡短摘要

  1. // check whether the str is a right IPv6 address

文章標籤

nicedoor 發表在 痞客邦 留言(0) 人氣()

在AndroidManifest中註冊相應的權限:

<uses-permission android:name="android.permission.FLASHLIGHT" />  

<uses-permission android:name="android.permission.CAMERA"/>

nicedoor 發表在 痞客邦 留言(1) 人氣()

 下面的程式可以將所有的網路介面和其關聯的 IP address 都顯示出來:

public String getPhoneIPAddrs()
{
    String sAddr = "";
    
    try
    {
        for (Enumeration<NetworkInterface> enumInterfaces =NetworkInterface.getNetworkInterfaces(); enumInterfaces.hasMoreElements(); )
        {
            // Get next network interface
            NetworkInterface interface = enumInterfaces.nextElement();
            
            for (Enumeration<InetAddress> enumIPAddrs =interface.getInetAddresses(); enumIPAddrs.hasMoreElements(); )
            {
                // Get next IP address of this interface
                InetAddress inetAddr = enumIPAddrs.nextElement();
                
                // Exclude loopback address
                if (!inetAddr.isLoopbackAddress())
                {
                    if (sAddr !"")
                    {
                        sAddr += ", ";
                    }
                    sAddr += "(" + interface.getDisplayName() + ") " + inetAddr.getHostAddress().toString();
                }
            }
        }
    }
    catch (SocketException e)
    {
        e.printStackTrace();
    }
    
    return sAddr;
}

nicedoor 發表在 痞客邦 留言(0) 人氣()