1

サーバーからファイルをダウンロードします。しかし、ファイルのサイズを取得したいときは常に body.contentLength()-1 を返します。この問題を解決する方法はいくつかありますHttpUrlConnectionが、ResponseBodyclass はどうですか?

  private void initDownload(){

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://mobleh.com/").build();    
        RequestInterface requestInterface = retrofit.create(RequestInterface.class);    
        Call<ResponseBody> request = requestInterface.getAPK(path);

        try {    
            downloadFile(request.execute().body());

        } catch (IOException e) {

            e.printStackTrace();
            Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();

        }
    }

    private void downloadFile(ResponseBody body) throws IOException {

        int count;
        byte data[] = new byte[1024 * 4];            
        long fileSize = body.contentLength();

}
4

1 に答える 1