Cleartext HTTP Traffic Not Permitted in android.

HTTP stands for hypertext transfer protocol. It transfers the data on the mobile applications network. Website uses the http protocol to send information on the internet, also called API. 

Difference between HTTP and HTTPS

The ‘s’  in HTTPS refers to secure. HTTPs in HTTP with encryption and verification . HTTps uses SSL to encrypt normal HTTP requests and responses. Website use both HTTP and HTTPS but mostly use HTTPS.

HTTP access issue in Android 

Android does not allow access to HTTP URL. it displays the error message that cleartext HTTP traffic is not permitted. As clear test support is disabled by default in android 9 of API level 28.

How to resolved error are mentioned in below code:

 Step 1: First try connecting the URL with https:// instead of http://
 Step 2: Allow​w to all connections to HTTP URLs.

Step 3:  to allow connection to website
Create a file network_security_config.xml file and path is /res/xml/network_security_config.xml
  <?xml version="1.0" encoding="utf-8"?>
          <domain-config cleartextTrafficPermitted="true">
          <domain includeSubdomains="true">

Step 4: below code written in AndroidManifest.xml file.
 <?xml version="1.0" encoding="utf-8"?>
 <manifest ...>
   <uses-permission android:name="android.permission.INTERNET" />

Step 5: required permission is Internet
  <uses-permission android:name="android.permission.INTERNET" />

Happy coding!


365Bloggy May 21, 2024
Share this post