24

I am trying to secure WebView from cleartext traffic. As mentioned in the documentation. I have to set android:usesCleartextTraffic as false to achieve this. But this works on API level 23 and above. My minimum sdk is 22. How can I make sure app doesn't crash or create any problem on device running below API level 23 ? Or how can I programmatically set that attribute value in the application tag in Manifest.xml ?

hata
  • 11,633
  • 6
  • 46
  • 69
sagar suri
  • 4,351
  • 12
  • 59
  • 122

2 Answers2

59

As suggested in an article @ Android Developers Blogspot:

You don’t have to set minSdkVersion or targetSdkVersion of your app to 23 (Android Marshmallow) to use android:usesCleartextTraffic. On older platforms, this attribute is simply ignored and thus has no effect.

Hope this solves your query.

Community
  • 1
  • 1
Mayank Bhatnagar
  • 2,120
  • 1
  • 12
  • 20
3

When you use usesCleartextTraffic in manifest, you get the following warning :

Attribute usesCleartextTraffic is only used in API level 23 and higher (current min is 19).

The default value of usesCleartextTraffic is as the following :

  • for apps that target API level 27 or lower is "true".
  • for apps that target API level 28 or higher default to "false".

This attribute was added in API level 23.

This flag is ignored on Android 7.0 (API level 24) and above if an Android Network Security Config is present.

https://developer.android.com/guide/topics/manifest/application-element https://android-developers.googleblog.com/2016/04/protecting-against-unintentional.html

oiyio
  • 5,219
  • 4
  • 42
  • 54