Android InputStream Internet Disconnect

后端 未结 1 963
慢半拍i
慢半拍i 2021-01-02 17:49

In my Android program, I have some code that downloads a file. This works fine, but since on a cell phone, you can be disconnected at any time, I need to change it do it rec

1条回答
  •  迷失自我
    2021-01-02 18:34

    Take a look here: http://developer.android.com/reference/java/nio/channels/SocketChannel.html

    EDIT (based on comment): http://www.jguru.com/faq/view.jsp?EID=72378

    So thoughts based on the above.... you might put the reading in a thread and periodically check to see if the thread has stopped reading data (update a shared variable probably). If it has kill the connection and the thread and deal with it however you need to.

    Another alternative is to not use the HTTPURLConnection and deal with the bits you need your self.

    0 讨论(0)
提交回复
热议问题