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
?

- 11,633
- 6
- 46
- 69

- 4,351
- 12
- 59
- 122
-
https://koz.io/android-m-and-the-war-on-cleartext-traffic/ – AskNilesh Feb 01 '18 at 04:21
-
So will this crash or create any problem on devices running lower then API 23 ? @NileshRathod – sagar suri Feb 01 '18 at 04:26
-
may be or may be not because I'm not sure about this because no more details in Android docs about it – AskNilesh Feb 01 '18 at 04:28
2 Answers
As suggested in an article @ Android Developers Blogspot:
You don’t have to set
minSdkVersion
ortargetSdkVersion
of your app to 23 (Android Marshmallow) to useandroid:usesCleartextTraffic
. On older platforms, this attribute is simply ignored and thus has no effect.
Hope this solves your query.

- 1
- 1

- 2,120
- 1
- 12
- 20
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

- 5,219
- 4
- 42
- 54