简体   繁体   English

Android上的WebView App无法访问互联网,而模拟器工作正常

[英]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.

相关问题 无法在Android模拟器中访问Internet - Cannot Access Internet in Android Emulator Android应用程序可以在模拟器上正常运行,但不能在真实设备上运行 - Android Application works fine on emulator but not on a real device Android:Internet可以在模拟器中运行,但不能在我的手机上运行 - Android: Internet works in emulator but not on my phone 在模拟器上执行我的Android应用程序时获得自觉。 (但是在电话上工作正常) - Getting exeception while executing my android app on emulator. (But its working fine on phone) android-android studio模拟器中的SSL问题,可以在手机上正常工作 - android - SSL problems in android studio emulator, works fine on phone 网站无法在android webview中加载,但可以在android浏览器中正常运行 - Website won't load in android webview but works fine in android browsers Android:清除并更新手势上的Webview可以在模拟器上而不是手机上运行 - Android: Clear and update webview on gesture works in emulator not on phone 无法使用 @Controller 获得响应,而 @RestController 工作正常 - Not able to get response with @Controller, while @RestController works fine android 应用程序适用于模拟器但不适用于真实设备 - android app works on emulator but not in real device Android Studio 应用程序可以在模拟器中运行,但不能在真实设备上运行 - Android Studio app works in emulator but not on a real device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM