nextcloud / nextcloud/android

Getting a file through an `Intent.ACTION_GET_CONTENT` crashes with an `NetworkOnMainThreadException`

Open
#12,375 0 comments 0 reactions 0 assignees View on GitHub
bug feature: document provider performance: misc stable-3.27
Dominant language
Kotlin
Stars
5.6k
Forks
2k
Avg merge
2d 18h
Merged PRs (30d)
92

Description

### ⚠️ Before posting ⚠️

- [X] This is a **bug**, not a question or an enhancement.
- [X] I've [searched for similar issues](https://github.com/nextcloud/android/issues) and didn't find a duplicate.
- [X] I've written a clear and descriptive title for this issue, not just "Bug" or "Crash".
- [X] I agree to follow Nextcloud's [Code of Conduct](https://nextcloud.com/contribute/code-of-conduct/).

### Steps to reproduce

My app uses `Intent.ACTION_GET_CONTENT` to import images from other apps. This works fine, but when choosing files from Nextcloud, it crashes in `ContentResolver.openInputStream(uri)` with a `NetworkOnMainThreadException`. The URI looks like this: `content://org.nextcloud.documents/document/c3ba2b01309dc14c98e3680438c5ea72%2F131`.

Apparently, the developers of the Signal app have experienced the same issue:
https://github.com/signalapp/Signal-Android/issues/13296

Steps to reproduce:
1. Install ImageMeter (https://play.google.com/store/apps/details?id=de.dirkfarin.imagemeter&hl=en&gl=US) and start it
2. press '+' in the bottom left corner, select "Import image"
3. choose any image file from Nextcloud
4. it will crash with that exception

Note: opening the image within the Nextcloud app and selecting "Open with" works fine.

````
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1012820649, result=-1, data=Intent { dat=content://org.nextcloud.documents/... flg=0x1 }} to activity {de.dirkfarin.imagemeter/de.dirkfarin.imagemeter.imagelibrary.ImageLibraryActivity}: android.os.NetworkOnMainThreadException
at android.app.ActivityThread.deliverResults(ActivityThread.java:5547)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5586)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2448)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8194)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Caused by: android.os.NetworkOnMainThreadException
at android.os.Parcel.createExceptionOrNull(Parcel.java:3067)
at android.os.Parcel.createException(Parcel.java:3041)
at android.os.Parcel.readException(Parcel.java:3024)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:153)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:814)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2043)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1858)
at android.content.ContentResolver.openInputStream(ContentResolver.java:1528)
...
````

### Expected behaviour

Should not crash.

### Actual behaviour

Crashes with `NetworkOnMainThreadException`

### Android version

14

### Device brand and model

Pixel 8 Pro

### Stock or custom OS?

Stock

### Nextcloud android app version

3.27.0

### Nextcloud server version

-

### Using a reverse proxy?

I don't know

### Android logs

_No response_

### Server error logs

_No response_

### Additional information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.