How to convert Android content url and use it to open file?
Hitokage last edited by Hitokage
Hey, I am using FileDialog in QML to pick a file on Android but the path I get is in this content:// format. Is there any way to convert this and use it for example as QFile url? Right now I'm getting (even after using toLocalFile() from QUrl ):
Filename: "content://com.android.providers.downloads.documents/document/381" QFSFileEngine::open: No file name specified
Working on a multiplatform mobile app so I'd like to be able to use this at least on iOS too.
EDIT: Since FileDialog seems to be having more problems in Android right now I have created my own file picker using FolderListModel and StandardPaths. It's not an answer to this question but it is probably safer solution that works on all platforms.
You need a file provider which will translate the file name into something that Java (or C++) backend can understand. Unfortunately it's platform-specific and quite complicated. My answer to this question might help, although it's incomplete (sorry!).
@Hitokage I would suggest taking a look at this blog post:
It is a rather in-depth post with working code that sends and receives files. It's not perfect but very good, you should be able to adapt it easily enough 😉
Hitokage last edited by
R-Type last edited by
with Qt 5.15.2 I can open and read content:// path directly passing it to QFile. According to this it is possible since Qt 5.13.
mahdi.ze last edited by
you can use CrossQFile. CrossQFile is a QFile that supports android uri.