简体   繁体   中英

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. If needed the user can press another button and transfer the content to another activity and use WebView to display said content on it.

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

Real device API level: 28

App development/target API: 21

As of API 28 HTTP clear text is no longer supported by default. You are likely interacting with HTTP content and it is good enough for the AVD level 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM