共享转换后删除图像

时间:2016-08-07 11:02:41

标签: android android-intent android-activity transition

我正在创建一个带有共享过渡动画的应用。为此我用图像创建了一个意图。但图像存储在设备上。但是如何在过渡后删除这个?

我在这里分享转型:

this

在这里,我收到了uri:

Bitmap photo = ((BitmapDrawable) drawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(getContentResolver(), photo, "pic", null);
Uri uri = Uri.parse(path);
intent.putExtra(Intent.EXTRA_STREAM, uri);

在这里我尝试删除图像,但它找不到它:

pic = extras.getParcelable(Intent.EXTRA_STREAM);

图片的示例路径:File fdlt = new File(pic.getPath()); if (fdlt.exists()) { if (fdlt.delete()) { Log.e("DELETED", "DELETED"); } else { Log.e("NOT DELETED", "NOT DELETED"); } } else { Log.e("FILE NOT FOUND", "FILE NOT FOUND"); }

2 个答案:

答案 0 :(得分:1)

File fdlt = new File(pic.getPath());
        if (fdlt.exists()) {
            if (fdlt.delete()) {
                Log.e("DELETED", "DELETED");
            } else {
                Log.e("NOT DELETED", "NOT DELETED");
            }
        } else {
            Log.e("FILE NOT FOUND", "FILE NOT FOUND");
        }

将此代码替换为以下代码。

        int size = 0;
        size = this.getContentResolver().delete(pic,
                null, null);
        if (size == 0) {
            Log.e("NOT DELETED", "NOT DELETED");
        } else {
            Log.e("DELETED", "DELETED");
        }

答案 1 :(得分:0)

您可以将图片存储在应用的缓存目录中,让Android负责删除它:DEMO