I have been trying to make a test Android application which asks a user to specify the file name and writes some data there. Starting from the default QtQuick Controls 2 application (Qt 5.7.0), I changed it to provide FileDialog:

Qt Code:
  1. import QtQuick 2.7
  2. import QtQuick.Dialogs 1.2
  3.  
  4. Page1Form
  5. {
  6. MessageDialog {
  7. id: messageDialog
  8. onAccepted: {
  9. Qt.quit()
  10. }
  11. }
  12.  
  13. FileDialog
  14. {
  15. id: saveFileDialog
  16. title: "Please save a file"
  17. folder: "/sdcard"
  18. selectExisting: false
  19.  
  20. onAccepted:
  21. {
  22. messageDialog.text = fileWriter.testWrite(saveFileDialog.fileUrl)
  23. messageDialog.visible = true
  24. }
  25. } // FileDialog
  26.  
  27. button1.onClicked: {
  28. saveFileDialog.visible = true
  29.  
  30. }
  31. button2.onClicked: {
  32. console.log("Button 2 clicked.");
  33. }
  34. }
To copy to clipboard, switch view to plain text mode 

In the main.cpp I have this:
Qt Code:
  1. #include <QGuiApplication>
  2. #include <QQmlApplicationEngine>
  3. #include <QQmlContext>
  4. #include <QQuickStyle>
  5. #include <QtCore>
  6.  
  7. #include "filewriter.h"
  8.  
  9.  
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13. QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  14. QGuiApplication app(argc, argv);
  15. QQuickStyle::setStyle("Material");
  16.  
  17.  
  18. qmlRegisterUncreatableType<FileWriter>("FileWriter", 1, 0, "FileWriter", "FileWriter is uncreatable.");
  19.  
  20. QQmlApplicationEngine engine;
  21. engine.rootContext()->setContextProperty("fileWriter", new FileWriter);
  22. engine.load(QUrl(QLatin1String("qrc:/main.qml")));
  23.  
  24. qDebug() << QProcess::systemEnvironment();
  25.  
  26. return app.exec();
  27. }
To copy to clipboard, switch view to plain text mode 

A couple of issues emerged:

First, with AA_EnableHighDpiScaling the file dialog is incorrectly displayed on my Sony Xperia Z3:
Screenshot_20170208-134332.jpg

However, the main window seems to look nice:
Screenshot_20170208-134245.jpg

Without dpi scaling it looks better, but it is still hardly usable:
Screenshot_20170208-141601.jpg
It's inconvenient to browse and I don't even see how to type a file name. Is there a more user-friendly way to select files/folders in QML? Any examples? It seems to be a common task.

Despite having added android.permission.WRITE_EXTERNAL_STORAGE to AndroidManifest.xml when I launch the application it has this permission disabled by default. So I have to go to settings on my phone and turn them on manually. Otherwise it doesn't see the SD card content. How can I activate this permission automatically?

Finally, even if I enable WRITE_EXTERNAL_STORAGE permission, FileDialog doesn't seem to honor folder: "/sdcard", showing some default location. But according to the system environment the path exists:
PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin", "ANDROID_BOOTLOGO=1", "ANDROID_ROOT=/system", "ANDROID_ASSETS=/system/app", "ANDROID_DATA=/data", "ANDROID_STORAGE=/storage", "EXTERNAL_STORAGE=/sdcard", "ASEC_MOUNTPOINT=/mnt/asec", "BOOTCLASSPATH=/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/apache-xml.jar:/system/framework/org.apache.http.legacy.boot.jar:/system/framework/tcmiface.jar:/system/framework/qcmediaplayer.jar:/system/framework/WfdCommon.jar:/system/framework/oem-services.jar:/system/framework/com.qti.dpmframework.jar:/system/framework/dpmapi.jar:/system/framework/com.qti.location.sdk.jar", "SYSTEMSERVERCLASSPATH=/system/framework/servi
Any help is appreciated