0

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

Rag
  • 101
  • 1
  • 11
  • 1
    *So i have an __ which does not connect to server. I don't know whats going on here.* Missing word? Can you describe the symptoms that you are seeing, ex. Exception Stack Trace no requests popping in fiddler even though the app doesn't complain, etc. – Omar Abdel Bari Sep 27 '20 at 00:00
  • I get an IOexception. – Rag Sep 27 '20 at 04:46
  • 1
    Could you provide the exception stack trace? – Omar Abdel Bari Sep 27 '20 at 04:56
  • I also get an error in the logcat which says a connection to "the url i am trying to connect to" was leaked. Did you forget to close the response body? – Rag Sep 27 '20 at 07:39
  • added exception stacktrace @OmarAbdelBari – Rag Sep 27 '20 at 08:17
  • It is a file not found exception so I'm wondering if the file created in *File file=new File(Environment.DIRECTORY_DOWNLOADS,"debug.apk");* was actually created. BTW there is a bool returned that tells you if it was successful or not. https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createNewFile() Also DownloadActivity does not appear in the stack trace but I see the first class directly in your project to appear is SettingsActivity. That's something that we can explore if the file did in fact get generated. Might be just because it's a callback. – Omar Abdel Bari Sep 27 '20 at 13:14
  • https://stackoverflow.com/questions/38380371/okhttp-avoid-leaked-connection-warning *"Did you forget to close the response body?"* usually happens because there are branches of code (likely when it hits exceptions) where the connection is not closed. The close statements should go into a finally block where you (minimum) would need to ensure you do a null check before trying to close each one. – Omar Abdel Bari Sep 27 '20 at 14:25
  • I am done with this urlconnection. Okhttp works good. – Rag Sep 27 '20 at 15:25

0 Answers0