Android: Strange behavior of DocumentFile InputStream

1.4k views Asked by At

Background

I have an application that uses Storage Access Framework.

It prompts a user to pick a directory to obtain permissions to work with files:

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);

Then allow user to select a JPG image in the directory:

DocumentFile pickedDir = DocumentFile.fromTreeUri(this, treeUri);
DocumentFile[] files = pickedDir.listFiles();
...
DocumentFile file = files[0]; // for example

Problem

One user has the following problem on Android 7.

When the program try to read the content of the file (JPEG image):

InputStream is = getContentResolver().openInputStream(file.getUri());
... // then read the stream in a standard way

The content is not the true content of the file, but some random garbage with word "CONSOLE" followed by zeros:

enter image description here

The file has the correct length and no error is risen, only the content is nonsense.

This behavior is unique and it's not reproducible on any other device.

Has anyone encounter anything like this?

0

There are 0 answers