捕获保存到自定义文件夹的新图像时如何同步 android 厨房

How Sync android galley when capture a new image which save to custom folder

我实现了一个捕获图像并将它们保存到我的自定义文件夹的应用程序。一切正常,但问题是,当我捕捉图像时,我的图库不同步。这意味着图库不显示新的捕获图像。为此我需要重启我的 phone.

这是我的图像捕获代码....

if (requestCode == 0 && resultCode == RESULT_OK) {
        String[] projection = {MediaStore.Images.ImageColumns.SIZE,
                MediaStore.Images.ImageColumns.DISPLAY_NAME,
                MediaStore.Images.ImageColumns.DATA,
                BaseColumns._ID,
                MediaStore.Images.ImageColumns.DATE_ADDED};
        final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
        final String selection = MediaStore.Images.Media.DATE_TAKEN + " > " + time;
        Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        CursorLoader loader = new CursorLoader(this, u,
                projection, selection, null, imageOrderBy);
        Cursor cursor = loader.loadInBackground();
        if (null != cursor && cursor.moveToFirst()) {
            ContentResolver cr = this.getContentResolver();
            cr.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    BaseColumns._ID + "=" + cursor.getString(3), null);
        }
        //showing image in image view
        cameraPicture = output.getPath();
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 4;
        Bitmap bitmap = BitmapFactory.decodeFile(cameraPicture, options);
        binding.imageView.setImageBitmap(bitmap);
        binding.imageView.setVisibility(View.VISIBLE);
    }

so how can i sync my android galley when i capture the image??? so that i can view this image immediately from galley.

保存文件后需要通知系统

 private void scanFile(String path) {

    MediaScannerConnection.scanFile(MainActivity.this,
            new String[] { path }, null,
            new MediaScannerConnection.OnScanCompletedListener() {

                public void onScanCompleted(String path, Uri uri) {
                    Log.i("TAG", "Finished scanning " + path);
                }
            });
}