应用程序未连接到服务器urlconnection

时间:2020-09-26 16:40:50

标签: java android urlconnection

所以我有一个不连接服务器的服务器。我不知道这是怎么回事。

这是我的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::EGL_BAD_ATTRIBUTE 2020-09-26 09:38:13.497 27085-27118 / com.testapp.test W / Adreno-EGL::EGL_BAD_ATTRIBUTE 2020-09-26 09:38:14.783 27085-28381 / com.testapp.test V /字体:CurFontPath:/system/fonts/Roboto-Regular.ttf 2020-09-26 09:38:14.783 27085-28381 / com.testapp.test D / Typeface:切换到android orgin ttf 2020-09-26 09:38:17.012 27085-27118 / com.testapp.test W / Adreno-EGL::EGL_BAD_ATTRIBUTE 2020-09-26 09:38:25.112 27085-27085 / com.testapp.test V /字体:CurFontPath:/system/fonts/Roboto-Regular.ttf 2020-09-26 09:38:25.112 27085-27085 / com.testapp.test D /字体:切换至android orgin ttf 2020-09-26 09:38:25.134 27085-27085 / com.testapp.test V /字体:CurFontPath:/system/fonts/Roboto-Regular.ttf 2020-09-26 09:38:25.134 27085-27085 / com.testapp.test D /字体:切换到android orgin ttf 2020-09-26 09:38:25.179 27085-27118 / com.testapp.test W / Adreno-EGL::EGL_BAD_ATTRIBUTE 2020-09-26 09:38:27.186 27085-27118 / com.testapp.test W / Adreno-EGL::EGL_BAD_ATTRIBUTE 2020-09-26 09:38:28.222 27085-28419 / com.testapp.test V /字体:CurFontPath:/system/fonts/Roboto-Regular.ttf 2020-09-26 09:38:28.222 27085-28419 / com.testapp.test D / Typeface:切换到android orgin ttf 2020-09-26 09:38:30.697 27085-27118 / com.testapp.test W / Adreno-EGL::EGL_BAD_ATTRIBUTE

异常堆栈跟踪: 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::EGL_BAD_ATTRIBUTE 2020-09-27 01:13:07.373 15138-15294 / com.testapp.test E / RenderScript:SETAFFINITY ret = -1 2020-09-27 01:13:07.373 15138-15293 / com.testapp.test E / RenderScript:SETAFFINITY ret = -1 2020-09-27 01:13:07.374 15138-15292 / com.testapp.test E / RenderScript:SETAFFINITY ret = -1 2020-09-27 01:13:09.225 15138-15173 / com.testapp.test W / Adreno-EGL::EGL_BAD_ATTRIBUTE 2020-09-27 01:13:10.833 15138-15288 / com.testapp.test W / System.err:java.io.FileNotFoundException:https://mywebpushapp.herokuapp.com/download 2020-09-27 01:13:10.834 15138-15288 / com.testapp.test W / System.err:at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251) 2020-09-27 01:13:10.834 15138-15288 / com.testapp.test W / System.err:at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210) 2020-09-27 01:13:10.834 15138-15288 / com.testapp.test W / System.err:at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(Unknown Source:0) 2020-09-27 01:13:10.835 15138-15288 / com.testapp.test W / System.err:at java.net.URL.openStream(URL.java:1059) 2020-09-27 01:13:10.835 15138-15288 / com.testapp.test W / System.err:at com.testapp.test.SettingsActivity $ 1.run(SettingsActivity.java:65) 2020-09-27 01:13:10.835 15138-15288 / com.testapp.test W / System.err:at android.os.Handler.handleCallback(Handler.java:790) 2020-09-27 01:13:10.835 15138-15288 / com.testapp.test W / System.err:at android.os.Handler.dispatchMessage(Handler.java:99) 2020-09-27 01:13:10.835 15138-15288 / com.testapp.test W / System.err:at android.os.Looper.loop(Looper.java:192) 2020-09-27 01:13:10.836 15138-15288 / com.testapp.test W / System.err:at android.os.HandlerThread.run(HandlerThread.java:65) 2020-09-27 01:13:10.843 15138-15288 / com.testapp.test V /字体:CurFontPath:/system/fonts/Roboto-Regular.ttf 2020-09-27 01:13:10.843 15138-15288 / com.testapp.test D / Typeface:切换到android orgin ttf 2020-09-27 01:13:12.741 15138-15173 / com.testapp.test W / Adreno-EGL::EGL_BAD_ATTRIBUTE

0 个答案:

没有答案