Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetworkSecurityConfig: No Network Security Config specified -- Android 7.0 error?

I have some problem for android 7.0.0.

I use volley library for my application, and it works well except for Android 7.0

Here is part of my code;

String url_goster = "http://185.126.217.71/clog.php";
RequestQueue requestQueue;

StringRequest request= new StringRequest(Request.Method.POST, url_goster, new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        JSONObject veri_json;
        try {
            veri_json = new JSONObject(response);
            JSONArray serial_no = veri_json.getJSONArray("Bilgiler");

            for (int i = 0; i< serial_no.length(); i++){
                JSONObject bilgis = serial_no.getJSONObject(i);

                // JSON olarak verileri çekiyoruz
                String GELEN_SERIAL = bilgis.getString("GELEN_SERIAL");
                String TERMINAL_ADI = bilgis.getString("TERMINAL_ADI");
                String SICAKLIK_T1 = bilgis.getString("SICAKLIK_T1");
                String SICAKLIK_T2 = bilgis.getString("SICAKLIK_T2");
                String SICAKLIK_T3 = bilgis.getString("SICAKLIK_T3");
                String SON_DATA = bilgis.getString("SON_DATA");
                String NEM_H1 = bilgis.getString("NEM_H1");
                String NEM_H2 = bilgis.getString("NEM_H2");
                String NEM_H3 = bilgis.getString("NEM_H3");
                String SENSOR_1_AD = bilgis.getString("SENSOR_1_AD");
                String SENSOR_2_AD = bilgis.getString("SENSOR_2_AD");
                String SENSOR_3_AD = bilgis.getString("SENSOR_3_AD");
                int SENSOR_SAYISI = bilgis.getInt("SENSOR_SAYISI");

                kisiler.add(new Kisi(TERMINAL_ADI, SON_DATA, SENSOR_1_AD, SENSOR_2_AD, SENSOR_3_AD, SICAKLIK_T1, SICAKLIK_T2, SICAKLIK_T3, NEM_H1, NEM_H2, NEM_H3, GELEN_SERIAL, SENSOR_SAYISI));
            }
        } catch (JSONException e) {
            Log.e("JSON ALIRKEN HATA",e.getLocalizedMessage());

            Toast.makeText(getApplicationContext(), "Server'a bağlanılırken bir hata ile karşılaşıldı.", Toast.LENGTH_SHORT).show();
        }
    }
    }, new Response.ErrorListener() {
           @Override
           public void onErrorResponse(VolleyError error) {

           }
       }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String> params = new HashMap<String,String>();
                params.put("ad",USER);
                return params;
            }
        };
        requestQueue.add(request);
    }

If I test my application on Android 7.0, the output of console is;

D/NetworkSecurityConfig: No Network Security Config specified, using platform default I/Choreographer: Skipped 127 frames! The application may be doing too much work on its main thread.

but this only happens Android 7.0 and application looks blank because it doesn't get a response from the internet

. How can i solve this problem ?

like image 558
Onurhan Akcay Avatar asked Dec 28 '16 15:12

Onurhan Akcay


3 Answers

There is no problem with this message:

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

The D/ indicates that this is a debugging message. It indicates that you do not have your own network security configuration defined, and so platform-default rules apply. This is perfectly fine.

application looks empty because it does not response from the internet

Near as I can tell, you are parsing some JSON, iterating over it, and populating kisiler. Perhaps kisiler is not connected to your UI.

like image 56
CommonsWare Avatar answered Oct 19 '22 04:10

CommonsWare


try adding this to the manifest.xml

<uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

and change the android emulator to pixel 2 API 28 from the AVD manager it worked for me in both windows and mac

like image 25
Malak Avatar answered Oct 19 '22 05:10

Malak


So, I don't think the previous answer was clear enough. (I spent a couple of hours trying to "debug" this)

If you're seeing this prompt, the fact that it says

D/ blablabla

means that this is a Debug, and not an error. It's more like a notification to let you know that you didn't specify the NetworkSecurityConfig, and that it decided by itself to set it to default. Nothing wrong.

Your error, however, will show itself as:

E/ blebleble

TL;DR You might be looking at the wrong place if you're trying to debug an error.

like image 44
Nicolas Shu Avatar answered Oct 19 '22 04:10

Nicolas Shu