人。我正在尝试从运行在ESP8266模块上的本地Web服务器中获取一些内容(它正在作为访问点,并且我将手机直接连接到它-我已经通过浏览器对其进行了测试,并且运行良好)。问题是当我的代码进入InputStream方法时,因为从本地服务器上获取我的logcat的答案需要花费大量时间(大约2或3分钟)。但令人奇怪的是,当从APP中退出并转到手机上的浏览器并对其进行更新时,服务器会立即做出响应,并且内容会显示在我的logcat中。我的代码和logcat是:
try {
url = new URL(urls[0]);
urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = urlConnection.getInputStream(); //It seems the problem is here
InputStreamReader reader = new InputStreamReader(in);
int data = reader.read();
Log.i("analog content", "here2");
while (data != -1) {
char current = (char) data;
result += current;
data = reader.read();
}
Log.i("analog content", result);
return result;
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),"Could not find weather :(",Toast.LENGTH_SHORT).show();
return null;
}
我的日志:
20-05-19 13:06:46.396 32406-32415 / com.example.myapplication I / zygote64:代码缓存收集后,代码= 30KB,数据= 23KB
2020-05-19 13:06:46.396 32406-32415 / com.example.myapplication I / zygote64:将代码缓存容量增加到128KB
2020-05-19 13:06:46.440 32406-32465 / com.example.myapplication I / vndksupport:此过程未配置sphal命名空间。而是从当前名称空间加载/vendor/lib64/hw/gralloc.msm8953.so。
2020-05-19 13:06:46.629 32406-32406 / com.example.myapplication W / View:dispatchProvideAutofillStructure():未布置,忽略
2020-05-19 13:06:46.635 32406-32406 / com.example.myapplication I / AssistStructure:展平的最终辅助数据:2348字节,包含1个窗口,9个视图
2020-05-19 13:07:00.697 32406-32406 / com.example.myapplication I / analog内容:here1
2020-05-19 13:07:00.729 32406-32543 / com.example.myapplication I / DpmTcmClient:RegisterTcmMonitor from:com.android.okhttp.TcmIdleTimerMonitor
2020-05-19 13:07:00.788 32406-32543 / com.example.myapplication D / NetworkSecurityConfig:未指定网络安全配置,使用平台默认值
2020-05-19 13:07:15.340 32406-32415 / com.example.myapplication I / zygote64:执行部分代码缓存收集,代码= 59KB,数据= 54KB
2020-05-19 13:07:15.340 32406-32415 / com.example.myapplication I / zygote64:代码缓存收集后,代码= 59KB,数据= 54KB
2020-05-19 13:07:15.340 32406-32415 / com.example.myapplication I / zygote64:将代码缓存容量增加到256KB
2020-05-19 13:07:16.908 32406-32415 / com.example.myapplication I / zygote64:编译器分配了6MB的空间来编译void android.view.ViewRootImpl.performTraversals()
2020-05-19 13:07:55.517 32406-32415 / com.example.myapplication I / zygote64:执行完整代码缓存收集,代码= 125KB,数据= 92KB
2020-05-19 13:07:55.518 32406-32415 / com.example.myapplication I / zygote64:代码缓存收集后,代码= 87KB,数据= 59KB
2020-05-19 13:08:56.425 32406-32543 / com.example.myapplication I / analog内容:here2
2020-05-19 13:08:56.440 32406-32543 / com.example.myapplication I / analog内容:{“模拟”:[“通图本”],“数字”:[5]}2020-05-19 13:09:09.281 32406-32417 / com.example.myapplication I / zygote64:已调用System.exit,状态:1
2020-05-19 13:09:09.281 32406-32417 / com.example.myapplication I / AndroidRuntime:VM退出,结果代码为1,跳过了清除。
如您所见,我得到了答案(在logcat行2020-05-19 13:08:56.440上,但是它花费太多,或者直到我使用浏览器并对其进行更新。
有人可以帮我吗?