Java NetworkSecurityConfig:未指定网络安全配置——Android 7.0 错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41365334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NetworkSecurityConfig: No Network Security Config specified -- Android 7.0 error?
提问by Onurhan Akcay
I have some problem for android 7.0.0.
我对 android 7.0.0 有一些问题。
I use volley library for my application, and it works well except for Android 7.0
我为我的应用程序使用了 volley 库,它运行良好,除了 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;
如果我在 Android 7.0 上测试我的应用程序,控制台的输出是;
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.
D/NetworkSecurityConfig:未指定网络安全配置,使用平台默认 I/Choreographer:跳过 127 帧!应用程序可能在其主线程上做了太多工作。
but this only happens Android 7.0 and application looks blank because it doesn't get a response from the internet
但这只会发生在 Android 7.0 并且应用程序看起来是空白的,因为它没有从互联网上得到响应
. How can i solve this problem ?
. 我怎么解决这个问题 ?
采纳答案by CommonsWare
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.
在D/
表示这是一个调试消息。它表示您没有定义自己的网络安全配置,因此平台默认规则适用。这完全没问题。
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.
据我所知,您正在解析一些 JSON,对其进行迭代并填充kisiler
. 也许kisiler
未连接到您的 UI。
回答by Nicolas Shu
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
D/布拉布拉布拉
means that this is a Debug, and notan 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.
意味着这是一个调试,而不是一个错误。它更像是一个通知,让您知道您没有指定 NetworkSecurityConfig,并且它自己决定将其设置为默认值。没有错。
Your error, however, will show itself as:
但是,您的错误将显示为:
E/ blebleble
E/ blebleble
TL;DR You might be looking at the wrong place if you're trying to debug an error.
TL;DR 如果您试图调试错误,您可能看错了地方。
回答by Malak
try adding this to the manifest.xml
尝试将其添加到 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
并将 android 模拟器从 AVD 管理器更改为 pixel 2 API 28 它在 windows 和 mac 中都适用于我