0

i'm trying to connect to api by kotlin in android. but i'm getting error either

No network Securituy Config Specified, using platform default.

or

Using Network Security from resource ntwork_security_config debugBuild:true.

i already add network_security_config.xml in res/xml folder. can anyone help me with this problem?

below are some screenshot

enter image description here

enter image description here

enter image description here

1
  • Neither of those are errors, they are just warnings letting you know which Security Config the app is using. Is your api call working or not? Commented Sep 25, 2019 at 8:37

3 Answers 3

2

Your network-security-config should be similar as below:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">enter domain here</domain>
    </domain-config>
</network-security-config>

Example:

If your network call sends request to this domain:

www.myapp.com/api/something

Then, your network-security-config will look like:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">www.myapp.com</domain>
    </domain-config>
</network-security-config>
Sign up to request clarification or add additional context in comments.

Comments

1

Try using this and remove android:usesCleartextTraffic="true" from the manifest.

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

Comments

0

you need to add this StrictMode Policy in onCreate of your class file..

StrictMode.ThreadPolicy policy = new 
StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

3 Comments

still same :( . will it matter if i called api in fragment?
No it doesn't matter
still getting error using network security config from network_security_config debugBuild:true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.