通过谷歌的视频群聊发送照片后删除了 [英] Picture got deleted after send via Google hangout

查看:155
本文介绍了通过谷歌的视频群聊发送照片后删除了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的应用程序来查看图片。然而,与普通意图发送图像后:

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!

然而,随着GooglePlusGallery应用程序发送的图片似乎并不存在这个问题。

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?

推荐答案

在这里同样的问题。我的应用程序甚至没有存储的写权限,所以我假设的Hangouts其实就是删除图像。

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;
    }
}

这篇关于通过谷歌的视频群聊发送照片后删除了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆