nfsmw010 / android-query

Automatically exported from code.google.com/p/android-query
0 stars 0 forks source link

Permission error when sending aquery cached file #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi Peter,

I think than my issue is simpler... because i only need to send a
cached image using email intend !
Supposing that there is an ImageView that contains an image. This
image is cached and has been already downloaded (and cached) using
AQuery!
The image path is similar to this: "/data/data/gr.develop4u.myprog/
cache/aquery/k0cvvjd2a17w7r9oph4ht3ov" , so I know my image's info!
When the user clicks on the imageview, I open an Intent.ACTION_SEND
passing the existing (local) image to the intent.
There, I get the error: " ERROR/Mms/media(232):
java.io.FileNotFoundException: /data/data/gr.develop4u.myprog/cache/
aquery/k0cvvjd2a17w7r9oph4ht3ov (Permission denied) "
It seems for some reason the new Intent cannot read the cached image.
As a result, the email message contains no attachment or empty
attachment.

Thank you in advance!

Original issue reported on code.google.com by tinyeeliu@gmail.com on 1 Oct 2011 at 1:46

GoogleCodeExporter commented 9 years ago
Seems like the file need to be placed in SDCard or other apps can't access it.

Try below to create a temp file with a better file name. Planning to add a 
function to do this in the future.

    private static final int SEND_REQUEST = 12;
    private File tempfile;

    public void image_send() throws IOException{

        String url = "http://www.vikispot.com/z/images/vikispot/android-w.png";

        File cached = aq.getCachedFile(url);

        File ext = Environment.getExternalStorageDirectory();
        File tempDir = new File(ext, "myapp");
        tempDir.mkdirs();

        File file = new File(tempDir, "hello.png");
        file.createNewFile();

        FileInputStream fis = new FileInputStream(cached);
        FileOutputStream fos = new FileOutputStream(file);

        AQUtility.copy(fis, fos);

        fis.close();
        fos.close();

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("image/jpeg");
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        startActivityForResult(Intent.createChooser(intent, "Share via:"), SEND_REQUEST);

        tempfile = file;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){

        if(tempfile != null){
            tempfile.delete();
            tempfile = null;
        }
    }

Original comment by tinyeeliu@gmail.com on 1 Oct 2011 at 3:10

GoogleCodeExporter commented 9 years ago

Original comment by tinyeeliu@gmail.com on 3 Oct 2011 at 11:34