[英]WebView App on android not able to access internet while emulator works fine
I am developing a small App which downloads a website using HttpUrlConnection by using ASyncTask and saves it to a string and then displays the content on a TextView on a press of a button. 我正在开发一个小型应用程序,它使用ASyncTask使用HttpUrlConnection下载网站并将其保存为字符串,然后按一下按钮就可以在TextView上显示内容。 If needed the user can press another button and transfer the content to another activity and use WebView to display said content on it.
如果需要,用户可以按另一个按钮并将内容传输到另一个活动,并使用WebView在其上显示所述内容。
The problem I am running into is that the App is able to download the content on the emulator but not on a real handheld device. 我遇到的问题是该应用程序能够在模拟器上下载内容,但不能在真正的手持设备上下载。 I have put the internet usage permission in the manifest.
我已将清单中的互联网使用权限。
AVD API level: 26 AVD API级别:26
Real device API level: 28 真实设备API级别:28
App development/target API: 21 应用开发/目标API:21
As of API 28 HTTP clear text is no longer supported by default. 从API 28开始,默认情况下不再支持HTTP明文。 You are likely interacting with HTTP content and it is good enough for the AVD level 26.
您可能正在与HTTP内容进行交互,这对于AVD级别26来说已经足够了。
Therefore to fix this, you must add the following to your manifest: 因此,要解决此问题,您必须将以下内容添加到清单中:
<application
...
android:usesCleartextTraffic="true"
This will allow you to continue to support HTTP traffic. 这将允许您继续支持HTTP流量。 However, if you go this route, you should be aware of the security risks and potentially use a network config file to limit the destination domains that you are interacting with less than ideal security.
但是,如果您采用此路由,则应注意安全风险,并可能使用网络配置文件来限制与之交互的目标域,而不是理想的安全性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.