我在ubuntu上使用eclipse + android SDK,並使用套接字運行測試活動服務器。儘管互聯網許可設置在清單上,但我無法在Android設備上獲得我的ip
我的清單有上網權限
<uses-permission android:name="INTERNET"/>
但是,當我使用查找我的IP設備上:
// gets the ip address of your device
private String getLocalIpAddress()
{
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().toString(); }
}
}
}
catch (SocketException ex)
{
Log.e("ServerActivity", ex.toString());
}
return null;
}
我得到一個異常的logcat的:
Java.net.SocketException: Permission denied
標籤:MyActivity,但我有清單上的互聯網許可。
,如果我嘗試手動將IP,當我使用插座,我也得到與TAG例外:System.err的
有關問題的一些想法?
在此先感謝。
你應該更仔細地檢查你的清單文件,你放置它使用權限標籤。我剛剛測試了代碼,它工作正常。 – 2012-01-11 15:23:03
其他項目的許可工作,我認爲是在正確的地方。但感謝評論。 – vgonisanz 2012-01-11 15:36:24