Image was deleted after sending via Google Hangout

I wrote a simple application for viewing images. However, after sending the image with the general intention:

        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("URLSTRING"));
        shareIntent.setType("image/jpeg");
        mActivity.startActivity(Intent.createChooser(shareIntent, "SHARE"));

The image can be sent successfully if I selected Google Hangout. But after that he leaves!

Tested with another file explorer application, and this is the same behavior!

However, the sent image with the GooglePlusGallery application does not look like this problem.

What is this trick? How to avoid image deletion?

0
source share
3 answers

I had the same issue with Hangouts. It seems that it deletes the file even if it fails to send it, so before calling the intent, always copy the file to a new temp file.

0

, , ContentProvider uri.

0

Same problem. My application didn’t even have permissions to write to the storage, so I assume that Hangouts actually deletes the images.

Therefore, instead of directly transferring the file, I make a copy first. Here's the complete solution:

Bitmap bm = BitmapFactory.decodeFile(filePath); // original image
File myImageToShare = saveToSD(bm); // this will make and return a copy
if (myImageToShare != null) {
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(myImageToShare));
    shareIntent.setType("image/jpeg");
    context.startActivity(Intent.createChooser(shareIntent, "Share using"));
}

private File saveToSD(Bitmap outputImage){
    File storagePath = new File(Environment.getExternalStorageDirectory() + yourTempSharePath);
    storagePath.mkdirs();

    File myImage = new File(storagePath, "shared.jpg");
    if(!myImage.exists()){
        try {
            myImage.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        myImage.delete();
        try {
            myImage.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    try {
        FileOutputStream out = new FileOutputStream(myImage);
        outputImage.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
        return myImage;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
0
source

All Articles