2015-10-13 66 views

回答

0

你應該能夠使用ConnectivityManager.getAllNetworks()獲得所連接的網絡陣列: http://developer.android.com/reference/android/net/ConnectivityManager.html#getAllNetworks()

然後Network.getSocketFactory()您連接的網絡。 SocketFactory將允許您檢查可以在連接上創建的Socket

http://developer.android.com/reference/android/net/Network.html#getSocketFactory()

從這一點,簡單地創建從一個SocketFactory.createSocket()Socket將有你想要的信息,像Socket.getLocalSocketAddress()

http://developer.android.com/reference/javax/net/SocketFactory.html#createSocket()

http://developer.android.com/reference/java/net/Socket.html

0

沒有WifiManager喜歡非Wifi的班級。

ConnectivityManager connectivityManager = (ConnectivityManager) getApplicationContext().getSystemService(Service.CONNECTIVITY_SERVICE); 


         Log.i("routes ", connectivityManager.getLinkProperties(connectivityManager.getActiveNetwork()).getRoutes().toString()); 
         Log.i("domains ", connectivityManager.getLinkProperties(connectivityManager.getActiveNetwork()).getDomains().toString()); 
         Log.i("ip address ", connectivityManager.getLinkProperties(connectivityManager.getActiveNetwork()).getLinkAddresses().toString()); 
         Log.i("dns address ", connectivityManager.getLinkProperties(connectivityManager.getActiveNetwork()).getDnsServers().toString());