Android: Refreshing the Gallery after saving new images

后端 未结 8 953
天涯浪人
天涯浪人 2020-12-02 19:20

So in my application I at one point save a bunch of images to a temporary folder, and I want them to show up immediately in the Gallery. Off of a reboot, they do, but otherw

8条回答
  •  长情又很酷
    2020-12-02 19:55

    I know its late but try this can working in all versions:

       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        Intent mediaScanIntent = new Intent(
                                Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                        Uri contentUri = Uri.fromFile(out); //out is your file you saved/deleted/moved/copied
                        mediaScanIntent.setData(contentUri);
                        this.sendBroadcast(mediaScanIntent);
                    } else {
                        sendBroadcast(new Intent(
                                Intent.ACTION_MEDIA_MOUNTED,
                                Uri.parse("file://"
                                        + Environment.getExternalStorageDirectory())));
                    }
    

提交回复
热议问题