android/storage-samples

getContentResolver().openInputStream(imageUri) throw FileNotFoundException

Opened this issue · 3 comments

uri: content://0@com.sec.android.gallery3d.provider/union/video/item/25473

stack:

cause by:
java.io.FileNotFoundException: Unable to get item com.sec.android.gallery3d.data.UnionSCloudVideo@882a3ac
android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:144)
android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:698)
android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1416)
android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1253)
android.content.ContentResolver.openInputStream(ContentResolver.java:973)

device:
SM-G9350;Android 8.0.0,level 26

permission:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

this happed on Samsung device.

@tanyang93 Which sample are you referring to?

@tanyang93 Which sample are you referring to?

I referring to https://developer.android.google.cn/training/data-storage/shared/documents-files?hl=zh-cn#java

code example

private String readTextFromUri(Uri uri) throws IOException {
    StringBuilder stringBuilder = new StringBuilder();
    try (InputStream inputStream =
            getContentResolver().openInputStream(uri);
            BufferedReader reader = new BufferedReader(
            new InputStreamReader(Objects.requireNonNull(inputStream)))) {
        String line;
        while ((line = reader.readLine()) != null) {
            stringBuilder.append(line);
        }
    }
    return stringBuilder.toString();
}

I have confirmed that this is a problem with Samsung Album, please close this issue