Android: Correctly downloading/saving an email attachement

前端 未结 2 2003
伪装坚强ぢ
伪装坚强ぢ 2021-01-24 12:56

I have an interesting problem: My application is designed to send and open up a zip full of files, and the zip has a special extension (easier for the user). I can zip up the fi

相关标签:
2条回答
  • 2021-01-24 13:45

    Check this out please: http://www.jondev.net/articles/Unzipping_Files_with_Android_(Programmatically)

    A guide to unzip files in android, hope it helps solve your problem

    0 讨论(0)
  • 2021-01-24 13:58

    I found the answer!!! Took a while, but at least it works now:

                try {
                InputStream attachment = getContentResolver()
                        .openInputStream(getIntent().getData());
                savedFile = new File(Environment
                        .getExternalStorageDirectory().getAbsolutePath(),
                        "temp" + System.currentTimeMillis() + ".psz");
                FileOutputStream f = new FileOutputStream(savedFile);
                byte[] buffer = new byte[1024];
                int len1 = 0;
                while ((len1 = attachment.read(buffer)) > 0) {
                    f.write(buffer);
                }
                f.close();
            } catch (Exception e) {
            }
    

    I just used this code to download the attachment and now everything works perfectly =D

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