Android App select file with Nextcloud App - File can't be read

I’m developing an Android App and want to support saving and restoring my backups using the nextcloud App.

  1. Backup is working (My own app is saving a zip file. The file can be shared with the nextcloud app and is then uploaded)

  2. Restore is not working yet. I’m sending an ACTION_GET_CONTENT intent and select the file from Nextcloud. The problem is that I can’t find a way to read the selected file. I tried different ways and even the one that worked from many different locations and apps is crashing. At least I can differentiate when the file was selected using nextcloud (uri authoritity org.nextcloud.documents)

val inputStream = context.contentResolver.openInputStream(uri) //uri returned from ACTION_GET_CONTENT by Nextcloud app

It always fails with FileNotFoundException:
Caused by: Error downloading file:
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(
at android.content.ContentProviderProxy.openTypedAssetFile(
at android.content.ContentResolver.openTypedAssetFileDescriptor(
at android.content.ContentResolver.openAssetFileDescriptor(
at android.content.ContentResolver.openInputStream(

Hope someone has an idea. Thanks

I’ve run into the same issue right now. Have you found a solution?

unfortunately no. I suppose there is a bug at the nextcloud’s content provider. But I’m quite lost with that issue.

I currently believe it depends on the thread where the content reading access happens. I’ve two types of implementation now one is broken (UIThread) and one is working without this issue.

Oh crazy…thanks for the threading hint!
For me it is exactly the other way round. Up to now I’ve tried to restore in UiThread.
When I wrap the code in a doAsync (Anko method) block it is actually working. The data was set to the object returned by getImport() before and is used when calling exec.

    context?.let {
        doAsync {
            val daoList = getBackupConfig().createDaos( it )
            getImport().exec( it, daoList )
            daoList.forEach { dao -> dao.close() }
            it.runOnUiThread {
                binding.txtImportLog.text = getImport().getImportLog()
                setButtonEnabledState( binding.btnImport, true )
            } }
1 Like

I also have this problem. I also get a longer content URL on my device, not just the device Id. Has this been reported on GitHub yet?