ContentResolver enthält nicht das gerade erstellte Bild in einer sofortigen Abfrage nach der Erstellung der Datei

Mit diesem Code kopiere ich ein Bild mitdocumentFile.createFile()

private void newcopyFile(File fileInput, String outputParentPath,
                            String mimeType, String newFileName) {

        DocumentFile documentFileGoal = DocumentFile.fromTreeUri(this, treeUri);

        String[] parts = outputParentPath.split("\\/");
        for (int i = 3; i < parts.length; i++) {
            if (documentFileGoal != null) {
                documentFileGoal = documentFileGoal.findFile(parts[i]);
            }
        }
        if (documentFileGoal == null) {
            Toast.makeText(MainActivity.this, "Directory not found", Toast.LENGTH_SHORT).show();
            return;
        }

        DocumentFile documentFileNewFile = documentFileGoal.createFile(mimeType, newFileName);

        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            outputStream = getContentResolver().openOutputStream(documentFileNewFile.getUri());
            inputStream = new FileInputStream(fileInput);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            if (outputStream != null) {
                byte[] buffer = new byte[1024];
                int read;
                if (inputStream != null) {
                    while ((read = inputStream.read(buffer)) != -1) {
                        outputStream.write(buffer, 0, read);
                    }
                }
                if (inputStream != null) {
                    inputStream.close();
                }
                inputStream = null;
                outputStream.flush();
                outputStream.close();
                outputStream = null;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

Und so frage ich @ ContentResolver Nach dem Erstellen eines Bildes, um meine Bildergalerie sofort mit dem Ergebnis der Abfrage zu aktualisieren, die Informationen über das neu erstellte Bild enthalten soll.

cursorPhotos = MainActivity.this.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    projectionsImages,
                    null,
                    null,
                    MediaStore.Images.Media.DATE_TAKEN + " DESC"
            );

Aber die sofortige Abfrage konnte das neu erstellte Bild nicht finden. Und wenn ich die Abfrage nach einem Moment erneut ausführe, ist das neu erstellte Bild im Ergebnis enthalten.

Es scheint, dass die Bereitstellung von Informationen für das neu erstellte Bild Zeit für @ benötigContentResolver (wenn ContentResolver dafür zuständig ist), da es im Hintergrund ausgeführt wird, während ich eine sofortige Abfrage ausführe.

Gibt es eine Methode oder einen Listener, die / der weiß, wann das neu erstellte Bild von @ registriert wirContentResolver?

Antworten auf die Frage(4)

Ihre Antwort auf die Frage