我在ubuntu上使用eclipse + android SDK,并使用套接字运行测试活动服务器。
我的清单有互联网许可
<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
关于这个问题的一些想法??
提前致谢。
答案 0 :(得分:2)
我认为你必须在清单xml中以这种方式写入权限:
<uses-permission android:name="android.permission.INTERNET"/>
而不仅仅是“INTERNET”。试试以防万一。