Commit 71673d59 authored by Karel Slaný's avatar Karel Slaný

Added experimental Android code for reading opened file names.

parent 60b67db9
QT += qml quick quickcontrols2 network xml sql widgets svg
android {
QT += androidextras
}
TEMPLATE = app
APP_NAME = Datovka
# winphone|winrt target.
......
......@@ -21,6 +21,9 @@
* the two.
*/
#if defined(Q_OS_ANDROID)
#include <QtAndroidExtras>
#endif /* defined(Q_OS_ANDROID) */
#include <QApplication>
#include <QCommandLineParser>
#include <QQmlApplicationEngine>
......@@ -111,6 +114,43 @@ int setupCmdLineParser(QCommandLineParser &parser)
return 0;
}
#if defined(Q_OS_ANDROID)
/*!
* @brief Obtain list of files to be opened with the application.
*
* @return List of paths.
*/
static
QStringList getAndroidArguments(void)
{
/*
* http://stackoverflow.com/questions/27771311/how-to-get-application-arguments-on-qt-for-android
*/
QAndroidJniObject activity(QtAndroid::androidActivity());
if (!activity.isValid()) {
return QStringList();
}
QAndroidJniObject intent(activity.callObjectMethod("getIntent",
"()Landroid/content/Intent;"));
if (!intent.isValid()) {
return QStringList();
}
QAndroidJniObject data(intent.callObjectMethod("getData",
"()Landroid/net/Uri;"));
if (!data.isValid()) {
return QStringList();
}
QAndroidJniObject path(data.callObjectMethod("getPath",
"()Ljava/lang/String;"));
if (!path.isValid())
return QStringList();
}
return QStringList(path.toString());
}
#endif /* defined(Q_OS_ANDROID) */
/*!
* @brief Registers QML types.
*
......@@ -164,7 +204,12 @@ int main(int argc, char *argv[])
/* Process command-line arguments. */
parser.process(app);
QStringList cmdLineFileNames(parser.positionalArguments());
QStringList cmdLineFileNames;
#if defined(Q_OS_ANDROID)
cmdLineFileNames = getAndroidArguments();
#else
cmdLineFileNames = parser.positionalArguments();
#endif /* defined(Q_OS_ANDROID) */
/* load global settings */
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment