Picture got deleted after send via Google hangout
Asked Answered
E

3

0

I have written a simple application to view pictures. However, after sending the picture with the common intent:

        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 picture can be successfully sent if I chose Google hangout. But it is deleted after that!

Tested with other file manager application (root explorer) and it is the same behavior!

However, sent picture with GooglePlusGallery application does not seem to have this problem.

What is the trick? How to avoid the picture to be deleted?

Eucalyptol answered 12/2, 2014 at 2:48 Comment(7)
The code you posted is probably not where the issue lies.Peru
I know since it works fine with all other app like gmail/g+Eucalyptol
My point is that we can't really help you if you're not giving us the code that's broken.Peru
My question is not about my code, it is about the trick of HangoutEucalyptol
You're not listening to what I'm saying... the bug is likely something you introduced elsewhere in the codebase. I find it hard to believe that Android will simply delete any photo that you sent through an intent.Peru
Have you ever tried? You're just believing what you want to believe... Stop comment if you don't have a clue...Eucalyptol
I asked you to show more code to try to help you find your bug, as I don't believe it lies in this small snippet. No need to get hostile. If you do find a solution, please post it here for whoever may run across this issue in the future.Peru
W
0

I had the same problem with Hangouts. It seems that it deletes the file even if it doesn't succeed to send it, thus always copy the file to a new temp file before calling the intent.

Wrier answered 6/3, 2014 at 14:54 Comment(0)
P
0

I had the same issue, I believe exposing a ContentProvider instead that an uri could solve.

Portray answered 12/3, 2014 at 15:36 Comment(0)
F
0

Same problem here. My app didn't even have storage write permissions, so I'm assuming Hangouts actually is deleting the images.

So instead of sharing the file directly, i make a copy first. Here's the full 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;
    }
}
Forseti answered 27/4, 2014 at 8:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.