如題在android 2.x, 3.x 可以使用

 

jmdns = JmDNS.create();

去得到正確的type 清單但是在android 4.x則無法使用

而在android 4.x中要使用以下方式才可以正常得到typ清單

 

android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) getSystemService(android.content.Context.WIFI_SERVICE);

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) };
InetAddress addr = InetAddress.getByAddress(byteaddr);
Log.i("KEVIN", "addr:"+addr);
jmdns = JmDNS.create(addr);

 

只要在create時帶上變數即可正常使用

arrow
arrow

    狼翔月影 發表在 痞客邦 留言(0) 人氣()