app does not connect to server urlconnection

92 Views Asked by At

So i have an which does not connect to server. I don't know whats going on here.

Here is my 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();


                }
            }
        });

    }

Also i tried using thread,ThreadPool but that did not work and i did add internet permssion in AndroidManifest.xml

the logs: 2020-09-26 09:38:11.432 27085-27085/com.testapp.test V/Typeface: CurFontPath: /system/fonts/Roboto-Regular.ttf 2020-09-26 09:38:11.432 27085-27085/com.testapp.test D/Typeface: switch to android orgin ttf

--------- beginning of system

2020-09-26 09:38:11.446 27085-27085/com.testapp.test V/Typeface: CurFontPath: /system/fonts/Roboto-Regular.ttf 2020-09-26 09:38:11.446 27085-27085/com.testapp.test D/Typeface: switch to android orgin ttf 2020-09-26 09:38:11.501 27085-27118/com.testapp.test W/Adreno-EGL: <qeglDrvAPI_eglGetConfigAttrib:612>: EGL_BAD_ATTRIBUTE 2020-09-26 09:38:13.497 27085-27118/com.testapp.test W/Adreno-EGL: <qeglDrvAPI_eglGetConfigAttrib:612>: EGL_BAD_ATTRIBUTE 2020-09-26 09:38:14.783 27085-28381/com.testapp.test V/Typeface: CurFontPath: /system/fonts/Roboto-Regular.ttf 2020-09-26 09:38:14.783 27085-28381/com.testapp.test D/Typeface: switch to android orgin ttf 2020-09-26 09:38:17.012 27085-27118/com.testapp.test W/Adreno-EGL: <qeglDrvAPI_eglGetConfigAttrib:612>: EGL_BAD_ATTRIBUTE 2020-09-26 09:38:25.112 27085-27085/com.testapp.test V/Typeface: CurFontPath: /system/fonts/Roboto-Regular.ttf 2020-09-26 09:38:25.112 27085-27085/com.testapp.test D/Typeface: switch to android orgin ttf 2020-09-26 09:38:25.134 27085-27085/com.testapp.test V/Typeface: CurFontPath: /system/fonts/Roboto-Regular.ttf 2020-09-26 09:38:25.134 27085-27085/com.testapp.test D/Typeface: switch to android orgin ttf 2020-09-26 09:38:25.179 27085-27118/com.testapp.test W/Adreno-EGL: <qeglDrvAPI_eglGetConfigAttrib:612>: EGL_BAD_ATTRIBUTE 2020-09-26 09:38:27.186 27085-27118/com.testapp.test W/Adreno-EGL: <qeglDrvAPI_eglGetConfigAttrib:612>: EGL_BAD_ATTRIBUTE 2020-09-26 09:38:28.222 27085-28419/com.testapp.test V/Typeface: CurFontPath: /system/fonts/Roboto-Regular.ttf 2020-09-26 09:38:28.222 27085-28419/com.testapp.test D/Typeface: switch to android orgin ttf 2020-09-26 09:38:30.697 27085-27118/com.testapp.test W/Adreno-EGL: <qeglDrvAPI_eglGetConfigAttrib:612>: EGL_BAD_ATTRIBUTE

exception stack trace: 2020-09-27 01:13:07.175 15138-15138/com.testapp.test V/Typeface: CurFontPath: /system/fonts/Roboto-Regular.ttf 2020-09-27 01:13:07.175 15138-15138/com.testapp.test D/Typeface: switch to android orgin ttf

--------- beginning of system

2020-09-27 01:13:07.188 15138-15138/com.testapp.test V/Typeface: CurFontPath: /system/fonts/Roboto-Regular.ttf 2020-09-27 01:13:07.188 15138-15138/com.testapp.test D/Typeface: switch to android orgin ttf 2020-09-27 01:13:07.207 15138-15288/com.testapp.test D/NetworkSecurityConfig: No Network Security Config specified, using platform default 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: <qeglDrvAPI_eglGetConfigAttrib:612>: 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: <qeglDrvAPI_eglGetConfigAttrib:612>: 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/Typeface: CurFontPath: /system/fonts/Roboto-Regular.ttf 2020-09-27 01:13:10.843 15138-15288/com.testapp.test D/Typeface: switch to android orgin ttf 2020-09-27 01:13:12.741 15138-15173/com.testapp.test W/Adreno-EGL: <qeglDrvAPI_eglGetConfigAttrib:612>: EGL_BAD_ATTRIBUTE

0

There are 0 best solutions below