android studio use cleartext http on api 17

232 Views Asked by At

I am using xammp server for php on localhost , i was working before update (i think), but now http connection gives me an exception:

W/System.err: java.io.IOException: Cleartext HTTP traffic to 192.168.0.105 not permitted

i have tried then to add android:usesCleartextTraffic="true" on Application for AndroidManifest , but also a next error:

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

I want to keep support to API 17, and when releasing my app I will use https on a public server, what can I do for now?

1

There are 1 best solutions below

0
Sairaj Sawant On

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.

Reference - https://android-developers.googleblog.com/2016/04/protecting-against-unintentional.html?m=1