更新时间:2022-06-08 06:37:02
我收到错误:
android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099).
android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099).
我在谷歌上搜索了这个错误并找到了这个链接:DefaultHttpClient to AndroidHttpClient - 这建议我包括在我的 onCreate 方法中使用以下代码.
I googled this error and came upon this link: DefaultHttpClient to AndroidHttpClient - which suggested I include the following code in my onCreate method.
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
现在可以工作了.事实上,Android 不再让网络操作在主线程上进行.
Now its working. In fact, Android does not let network operations be performed on the main thread any longer.