Reputation: 713
I am trying to make a database via 000webhost.com. I keep getting this message showing in the event log whenever I run the app from android studio. Does anyone knows how to solve this problem? Much appreciated!
Upvotes: 70
Views: 209361
Reputation: 1
I think figured it out
When Android is loading it's trusted anchors, it is by default would use the network_security_config file for it, as long as you provided one.
BUT!
If you are connecting using OKHTTP3 (that what reproduced it for me) before your activity have launched, on a static initialiser for example, Android would not have time to load the network security config from the application, and would use the platform config by default instead of the one you provided.
I hope this help someone
Upvotes: 0
Reputation: 4037
Image is vivid.
file network_security_config.xml
file manifest
to copy & paste is easy
copy xml & key line in manifest
Upvotes: 7
Reputation: 445
This occurs to the api 28 and above, because doesn't accept http anymore, you need to change if you want to accept http or localhost requests.
Create an XML file
Add the following code on the new XML file you created
Add this on AndroidManifest.xml
Upvotes: 3
Reputation: 1
I know i'm late for the answer, but it might help someone. If you still having this problem, you probably didn't put the method , that makes the request, in a Thread
Upvotes: 0
Reputation: 328
Check the URL it should be using https rather than http protocol.
In my case changing http to https in the URL solved it.
Upvotes: 14
Reputation: 433
I have a same problem, with volley, but this is my solution:
In Android Manifiest, in tag application add:
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
create in folder xml this file network_security_config.xml and write this:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
inside tag application add this tag:
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
Upvotes: 26
Reputation: 1248
I had also the same problem. Please add this line in application tag in manifest. I hope it will also help you.
android:usesCleartextTraffic="true"
Upvotes: 61
Reputation: 515
I just had the same problem. It is not a network permission but rather thread issue. Below code helped me to solve it. Put is in main activity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9)
{
StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
Upvotes: 18
Reputation: 457
The message you're getting isn't an error; it's just letting you know that you're not using a Network Security Configuration. If you want to add one, take a look at this page on the Android Developers website: https://developer.android.com/training/articles/security-config.html.
Upvotes: 24