Android Pie: WebView showing error for plain HTTP on some sites, even with usesClearTextTraffic=“true”

后端 未结 1 1481
轻奢々
轻奢々 2021-01-04 13:15

We have a WebView in our android app that end users can browse to whatever site they want. Android Pie disabled plain HTTP by default, so we added usesClearTextTraffic=\"tru

相关标签:
1条回答
  • 2021-01-04 13:28

    Solution:

    As I've observed the Manifest.xml of yours, you have used the android:usesCleartextTraffic="true" in the <activity> tag.

    As you can see in the Documentation of the activity tag, it does not offer any functionality as such in the syntax provided in the docs.

    As you can see in the screenshot below, the description of the cleartexttraffic is quite straight forward.

    Also, if you look at the Documentation of the application tag, you will notice that android:usesCleartextTraffic is one of the attributes of the Application Tag.

    So the only fix required here is to remove the attribute in from the activity tag and use it in the application tag and there is no activity tag support for android:usesCleartextTraffic.

    Starting with Android 9 (Pie) Clear Text Traffic is disabled by default.

    Hence, the solution would be:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest ...>
        <uses-permission android:name="android.permission.INTERNET" />
        <application
            ...
            android:usesCleartextTraffic="true"
            ...>
            ...
        </application>
    </manifest>
    

    Try it, Please comment if you have any issues related to this.

    0 讨论(0)
提交回复
热议问题