问题描述
这是我的DownloadActivity.java:
public void onClickUpdate(View view) throws IOException {
HandlerThread handlerThread=new HandlerThread("test");
handlerThread.setPriority(1);
handlerThread.start();
Looper looper=handlerThread.getLooper();
Handler handler=new Handler(looper);
handler.post(new Runnable() {
@Override
public void run() {
try {
String url="theurl";
URL u = new URL(url);
URLConnection conn = u.openConnection();
conn.addRequestProperty("version",version);
conn.setConnectTimeout(15000);
conn.connect();
int contentLength = conn.getContentLength();
DataInputStream stream = new DataInputStream(u.openStream());
byte[] buffer = new byte[contentLength];
stream.readFully(buffer);
stream.close();
File file=new File(Environment.DIRECTORY_DOWNLOADS,"debug.apk");
file.createNewFile();
DataOutputStream fos = new DataOutputStream(new FileOutputStream(file));
fos.write(buffer);
fos.flush();
fos.close();
fos=null;
conn=null;
stream=null;
} catch(IOException e) {
Toast.makeText(SettingsActivity.this,"hit different error",Toast.LENGTH_LONG).show();
}
catch(Exception e){
e.printstacktrace();
}
}
});
}
我也尝试使用thread,ThreadPool,但这没有用,我确实在AndroidManifest.xml中添加了互联网权限
日志: 2020-09-26 09:38:11.432 27085-27085 / com.testapp.test V /字体:CurFontPath:/system/fonts/Roboto-Regular.ttf 2020-09-26 09:38:11.432 27085-27085 / com.testapp.test D / Typeface:切换至android orgin ttf
--------- beginning of system
2020-09-26 09:38:11.446 27085-27085 / com.testapp.test V /字体:CurFontPath:/system/fonts/Roboto-Regular.ttf
2020-09-26 09:38:11.446 27085-27085 / com.testapp.test D / Typeface:切换到android orgin ttf
2020-09-26 09:38:11.501 27085-27118 / com.testapp.test W / Adreno-EGL:
异常堆栈跟踪: 2020-09-27 01:13:07.175 15138-15138 / com.testapp.test V /字体:CurFontPath:/system/fonts/Roboto-Regular.ttf 2020-09-27 01:13:07.175 15138-15138 / com.testapp.test D / Typeface:切换到android orgin ttf
--------- beginning of system
2020-09-27 01:13:07.188 15138-15138 / com.testapp.test V /字体:CurFontPath:/system/fonts/Roboto-Regular.ttf
2020-09-27 01:13:07.188 15138-15138 / com.testapp.test D / Typeface:切换到android orgin ttf
2020-09-27 01:13:07.207 15138-15288 / com.testapp.test D / NetworkSecurityConfig:未指定网络安全配置,使用平台默认值
2020-09-27 01:13:07.217 15138-15288 / com.testapp.test I / DpmTcmClient:RegisterTcmMonitor from:com.android.okhttp.TcmIdleTimerMonitor
2020-09-27 01:13:07.223 15138-15288 / com.testapp.test I / DpmTcmClient:RegisterTcmMonitor from:com.android.okhttp.TcmIdleTimerMonitor
2020-09-27 01:13:07.231 15138-15173 / com.testapp.test W / Adreno-EGL:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)