Android emulator:如何以编程方式刷新图像库?

Android emulator:如何以编程方式刷新图像库?,android,refresh,android-sdcard,android-gallery,android-image,Android,Refresh,Android Sdcard,Android Gallery,Android Image,我被卡住了,所以我希望有人能帮我:)我有一个活动,我可以从gallery加载图像,然后它显示在屏幕上。在那个屏幕上,我可以选择删除那个图像。当我选择删除图像的选项时,图像已成功删除,但当我选择加载其他图像时,图像仍显示在库中。所以,用户仍然可以从图库中选择旧图片,但在这种情况下,它不会显示在屏幕上,因为它已被删除。删除图片后如何刷新库 我试过这个,但似乎不起作用: sendBroadcast(new Intent( Intent.ACTION_MEDIA_MOUNTED,

我被卡住了,所以我希望有人能帮我:)我有一个活动,我可以从gallery加载图像,然后它显示在屏幕上。在那个屏幕上,我可以选择删除那个图像。当我选择删除图像的选项时,图像已成功删除,但当我选择加载其他图像时,图像仍显示在库中。所以,用户仍然可以从图库中选择旧图片,但在这种情况下,它不会显示在屏幕上,因为它已被删除。删除图片后如何刷新库

我试过这个,但似乎不起作用:

sendBroadcast(new Intent(
            Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" +  Environment.getExternalStorageDirectory())));

我希望避免每次删除某些图像时都手动扫描SD卡。

问题是,我在删除图像时传递的是图像URI,而不是绝对路径,因此它不成功。代码应该是这样的

File file = new File("some URI I received as a result of one method")
path = file.getAbsolutePath();
File f = new File(path);
    if (f.exists()) {
        if (f.delete()) {
            Log.w("DELETED","file Deleted");
        } else {
            Log.w("NOT DELETED","file not Deleted");
        }
    }

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" +  Environment.getExternalStorageDirectory())));

    imageViewField.setImageBitmap(null);

所以,该方法可以工作,但文件根本没有被删除,所以它仍然在库中。

问题是我在删除时传递的是图像URI,而不是绝对路径,所以它不成功。代码应该是这样的

File file = new File("some URI I received as a result of one method")
path = file.getAbsolutePath();
File f = new File(path);
    if (f.exists()) {
        if (f.delete()) {
            Log.w("DELETED","file Deleted");
        } else {
            Log.w("NOT DELETED","file not Deleted");
        }
    }

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" +  Environment.getExternalStorageDirectory())));

    imageViewField.setImageBitmap(null);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
        Uri.parse("file://" +  Environment.getExternalStorageDirectory())));
所以,这个方法是有效的,但文件并没有被删除,所以它仍然在库中

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
        Uri.parse("file://" +  Environment.getExternalStorageDirectory())));
我在froyo中使用了上面的代码,结果代码在froyo中运行良好

我在froyo中使用了上面的代码,结果代码在froyo中运行良好