在Android模拟器网络访问 [英] Network access in Android emulator
本文介绍了在Android模拟器网络访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过我的Android应用程序将达到互联网,但我都成功和失败。
I'm trying to reach internet through my Android app, but I both succeed and fail.
我启动模拟器,当我建立我的应用程序,该应用程序安装就好了。我可以使用浏览器访问互联网,但是,当我尝试这个小code片段...
I start the emulator when I build my app, and the app is installed just fine. I can use the browser to access the internet, however, when I try this small code snippet ...
InetAddress inet;
try {
inet = InetAddress.getByName("www.google.com");
System.out.println ("IP : " + inet.getHostAddress());
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
...这一切失败。
... it all fails.
时有没有设置你必须做,以使应用程序访问互联网?
Is there any setting you must do to make the app reach the internet?
推荐答案
您必须添加到您的清单文件:
You must add this to your manifest file:
<uses-permission android:name="android.permission.INTERNET" />
,要求授权从您的应用程序访问网络
to demand authorization to access internet from your app
这篇关于在Android模拟器网络访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文