Search code examples
androidkotlinrequestconnection

**D/NetworkSecurityConfig: No Network Security Config specified, using platform default**


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools" package="com.example.kotlin">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:networkSecurityConfig="@xml/network_security_config"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
            tools:ignore="GoogleAppIndexingWarning">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

this is manifest .xml

and ı add an network security confıg at the xml folder

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

And my code

package com.example.kotlin

import android.app.DownloadManager
import android.content.Context
import android.net.ConnectivityManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import com.android.volley.Request
import com.android.volley.Response
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
import org.w3c.dom.Text
import android.os.StrictMode
import androidx.core.content.getSystemService


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val btn_click_me = findViewById(R.id.button) as Button

        btn_click_me.setOnClickListener {
        request()
        }

        val cm= baseContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val networkinfo=cm.activeNetworkInfo
        if (networkinfo != null && networkinfo.isConnected)
        {
            Toast.makeText(baseContext, "Connected",Toast.LENGTH_LONG).show()
        }

    }
    fun request(){
        val tw=findViewById(R.id.textView) as TextView
        val queue = Volley.newRequestQueue(this)
        val url = "https://www.google.com"
        val stringRequest = StringRequest(Request.Method.GET, url,
            Response.Listener<String> { response ->
                // Display the first 500 characters of the response string.
                tw.text = "Response is: ${response.substring(0, 500)}"
            },
            Response.ErrorListener { tw.text = "That didn't work!" })

// Add the request to the RequestQueue.
        queue.add(stringRequest)


    }
}

ı checked the ınternet connectıon of the emulator and ıt says there ıs a connectıon so emulator has connectıon but ı stıll had :

**D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true**

this error before ı take securıty confıg ıt has saıd that :

**D/NetworkSecurityConfig: No Network Security Config specified, using platform default**

What should ı do for take the request how can ı pass thıs ınternet permıssıon thıng.

ı looked the other entries of thıs title but they couldnt help me so ı make a new entry

support security android


Solution

  • You have to reset your emulator after give permissons and set manifest xml.