My network requests are not working in Android Pie!

Nikit Bhandari
Feb 23 · 2 min read

Recently I faced a weird situation where my app was working fine in all Android versions except Android Pie.

After lots of debugging I came to know it was because my server was not secure ie it was using HTTP (not HTTPS). Android P uses HTTPS by default. What this means is that if you are using unencrypted HTTP requests in your app, the app will work fine in all versions of Android except Android P.

Let’s consider two situations where your app won’t work properly in Android P. Firstly, if your server is on HTTP obviously it won’t work in Android P. Another case is when your server is on HTTPS but it is returning something like an image URL which is HTTP, you won’t be able to load the image in Android P.

The good news is… there is a really simple and quick fix for the above problem so let’s get started.

You just need to create a network_security_config file in the xml folder and then include it in the manifest in the following manner.

The network_security_config file looks like this.

Here you can simply mention the domain name of your server or all the domain names that are using HTTP.

This is it! Now your app will work properly in Android Pie otherwise you would have got no response from the server and your users would have uninstalled your app.

Thanks for reading! If you enjoyed this story, please click the 👏 button and share to help others! Feel free to leave a comment 💬 below. Have feedback? Let’s connect on Twitter.

MindOrks

Our community publishes stories worth reading on software development and design. Android | Machine Learning | #MakeEveryoneCode

Nikit Bhandari

Written by

Android developer -> Find more about me here https://nikit19.github.io/

MindOrks

MindOrks

Our community publishes stories worth reading on software development and design. Android | Machine Learning | #MakeEveryoneCode

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade