Monday, August 7, 2017

Qt on Android: browsing files from device with QFileDialog widget in Linux

I was developing an Android application with Qt using a real device connected to my laptop with Lubuntu, and I needed to open files created by such application on Android's file system directly from my PC. The thing is, the device was auto-mounted whenever I connected it, and showing properly in the file manager (something like mtp://[usb:001,007]/), but while using QFileDialog::getOpenFileName there was no way to find the device and browse its folder structure.

Fortunately, this wiki page brought the much needed help. The mounted device will be available in a directory that begins with mtp:host= and is located under /run/user/$UID/gvfs/ where $UID is the user name. And that's it, the whole Android device's file system can be browsed from that folder on, with even automatic refresh when a file is created/removed.

No comments:

Post a Comment