Android 8: Cleartext HTTP traffic not permitted

Matheus Mello
Matheus Mello
September 2, 2023
Cover Image for Android 8: Cleartext HTTP traffic not permitted

Android 8: Cleartext HTTP Traffic Not Permitted 😱

Are you experiencing issues with your Android 8 app not showing content from the backend feed? 😩 Don't worry, you're not alone! Many users have reported encountering the following Exception on Android 8:

08-29 12:03:11.246 11285-11285/ E/: [12:03:11.245, main]: Exception: IOException java.io.IOException: Cleartext HTTP traffic to * not permitted

But fear not! I'm here to help you troubleshoot and resolve this problem. Let's dive in! 🏊‍♂️

Understanding the Exception 😕

The exception message is pretty clear - "Cleartext HTTP traffic to * not permitted." This means that Android 8 (Oreo) has stricter security measures in place and does not allow unencrypted HTTP connections by default. This change aims to enhance the overall security of the operating system. 🛡️

Solution 1: Setting the android:usesCleartextTraffic Flag 🚩

Some developers may find success by explicitly setting the android:usesCleartextTraffic flag in the app's manifest file. However, in most cases, this flag is set to true by default, so manually setting it may not provide a solution. 📝

Solution 2: Using Network Security Configuration 🌐

Android 8 introduced a new approach to handle network security called Network Security Configuration. This configuration file lets you specify which domains or URLs can be accessed using cleartext traffic. By default, it blocks all HTTP traffic unless explicitly allowed.

To get your app working again, follow these steps:

  1. Create a new XML file called network_security_config.xml in your app's resource directory (e.g., res/xml/network_security_config.xml).

  2. Add the following code to the network_security_config.xml file:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">your-domain.com</domain>
    </domain-config>
</network-security-config>

In this example, we allow cleartext traffic for the domain your-domain.com. Replace it with the actual domain(s) your app needs to access.

  1. Modify your app's manifest file (AndroidManifest.xml) to include the following lines of code:

<application
    android:networkSecurityConfig="@xml/network_security_config"
    ...
>
    ...
</application>
  1. Rebuild and run your app, and voila! Your app should now be able to access the backend feed and display the content on Android 8 devices. 🥳

Conclusion and Call-to-Action ✅

In this blog post, we explored the common issue of Cleartext HTTP traffic not being permitted on Android 8 devices. We provided two solutions: setting the android:usesCleartextTraffic flag and using Network Security Configuration.

If you're facing this problem, give these solutions a try and let us know if they worked for you. Share your experience and any additional insights in the comments below. Happy coding! 🚀👩‍💻👨‍💻

Take Your Tech Career to the Next Level

Our application tracking tool helps you manage your job search effectively. Stay organized, track your progress, and land your dream tech job faster.

Your Product
Product promotion

Share this article

More Articles You Might Like

Latest Articles

Cover Image for How can I echo a newline in a batch file?
batch-filenewlinewindows

How can I echo a newline in a batch file?

Published on March 20, 2060

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Cover Image for How do I run Redis on Windows?
rediswindows

How do I run Redis on Windows?

Published on March 19, 2060

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Cover Image for Best way to strip punctuation from a string
punctuationpythonstring

Best way to strip punctuation from a string

Published on November 1, 2057

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Cover Image for Purge or recreate a Ruby on Rails database
rakeruby-on-railsruby-on-rails-3

Purge or recreate a Ruby on Rails database

Published on November 27, 2032

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my