VLC for Android cannot open URIs from FileProvider
== Repro steps: 0. Install VLC for Android from Play Store (current: 3.2.3)
- Clone GitHub repo https://github.com/android/camera-samples
- Open Android Studio project Camera2SlowMotion
- Build and run the sample on a device capable of slow motion capture
- Capture a video by long-pressing the screen
- Select VLC as the application to view the video
== Result: Application crashes. See below for stack trace.
== Expected: VLC plays the slow motion video. The file is being shared with VLC via FileProvider in the following manner:
// Launch external activity via intent to play video recorded using our provider
startActivity(Intent().apply {
action = Intent.ACTION_VIEW
type = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(outputFile.extension)
val authority = "${BuildConfig.APPLICATION_ID}.provider"
data = FileProvider.getUriForFile(view.context, authority, outputFile)
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_ACTIVITY_CLEAR_TOP
})
Other applications, such as Google Photos, are able to open the file. Note that the provider cannot be exported (app refuses to start otherwise in recent versions of Android) and the URI permissions are being granted:
<!-- FileProvider used to share media with other apps -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
== Stack trace:
2019-12-06 16:28:03.469 11169-11247/com.android.example.camera2.slowmo E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.android.example.camera2.slowmo.provider/files/VID_2019_12_06_16_27_55_611.mp4 from pid=11857, uid=10397 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:729)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:602)
at android.content.ContentProvider$Transport.query(ContentProvider.java:231)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:104)
at android.os.Binder.execTransactInternal(Binder.java:1021)
at android.os.Binder.execTransact(Binder.java:994)
2019-12-06 16:28:03.481 11169-11247/com.android.example.camera2.slowmo E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.android.example.camera2.slowmo.provider/files/VID_2019_12_06_16_27_55_611.mp4 from pid=11857, uid=10397 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:729)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:602)
at android.content.ContentProvider$Transport.enforceFilePermission(ContentProvider.java:593)
at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:507)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:307)
at android.os.Binder.execTransactInternal(Binder.java:1021)
at android.os.Binder.execTransact(Binder.java:994)
2019-12-06 16:28:03.482 11857-11894/? E/VLC/FileUtils: Permission is no longer valid