Commit c987994a authored by Camilo Higuita's avatar Camilo Higuita

add file chooser intent fro android

parent d77eff7f
This diff is collapsed.
#include "android.h"
#include "android/notificationclient.h"
#include <QDebug>
#include <QException>
class InterfaceConnFailedException : public QException
{
public:
void raise() const { throw *this; }
InterfaceConnFailedException *clone() const { return new InterfaceConnFailedException(*this); }
};
Android::Android(QObject *parent) : QObject(parent)
{
}
void Android::handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data)
{
qDebug()<< "ACTIVITY RESULTS";
jint RESULT_OK = QAndroidJniObject::getStaticField<jint>("android/app/Activity", "RESULT_OK");
if (receiverRequestCode == 42 && resultCode == RESULT_OK)
{
QString url = data.callObjectMethod("getData", "()Landroid/net/Uri;").callObjectMethod("getPath", "()Ljava/lang/String;").toString();
emit folderPicked(url);
}
}
void Android::fileChooser()
{
QAndroidJniEnvironment _env;
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;"); //activity is valid
if (_env->ExceptionCheck()) {
_env->ExceptionClear();
throw InterfaceConnFailedException();
}
if ( activity.isValid() )
{
QAndroidJniObject::callStaticMethod<void>("com/example/android/tools/SendIntent",
"fileChooser",
"(Landroid/app/Activity;)V",
activity.object<jobject>());
if (_env->ExceptionCheck()) {
_env->ExceptionClear();
throw InterfaceConnFailedException();
}
}else
throw InterfaceConnFailedException();
}
#ifndef ANDROID_H
#define ANDROID_H
#include <QAndroidActivityResultReceiver>
#include <QObject>
#include <QAndroidJniObject>
#include <QAndroidJniEnvironment>
#include <QtAndroid>
class Android : public QObject
class Android : public QObject, public QAndroidActivityResultReceiver
{
Q_OBJECT
public:
explicit Android(QObject *parent = nullptr);
Q_INVOKABLE void fileChooser();
virtual void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject & data);
private:
QAndroidActivityResultReceiver *resultReceiver;
signals:
void folderPicked(const QString &url);
public slots:
};
#endif // ANDROID_H
\ No newline at end of file
#endif // ANDROID_H
......@@ -10,6 +10,8 @@ import java.io.File;
public class SendIntent
{
private static final int READ_REQUEST_CODE = 42;
public static void sendText(Activity context,String text)
{
Intent sendIntent = new Intent();
......@@ -53,12 +55,14 @@ public class SendIntent
intent.setDataAndType(uri, mime);
context.startActivity(Intent.createChooser(intent, "Open folder"));
// Intent sendIntent = new Intent();
// sendIntent.setAction(Intent.ACTION_VIEW);
// sendIntent.setDataAndType(uri, mime);
// sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(sendIntent);
}
public static void fileChooser(Activity context)
{
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("audio/*");
context.startActivityForResult(intent, READ_REQUEST_CODE);
}
}
......@@ -25,6 +25,7 @@
#if defined(Q_OS_ANDROID)
#include "android/notificationclient.h"
#include "android/android.h"
#include <QAndroidJniObject>
#include <QAndroidJniEnvironment>
#include <QtAndroid>
......@@ -96,6 +97,12 @@ Babe::Babe(QObject *parent) : CollectionDB(parent)
});
#elif defined (Q_OS_ANDROID)
this->nof = new NotificationClient(this);
this->android = new Android(this);
connect(android, &Android::folderPicked, [this](const QString &url)
{
qDebug()<< "Folder picked"<< url;
});
#endif
}
......@@ -427,6 +434,14 @@ void Babe::openFile(const QString &url)
}
void Babe::fileChooser()
{
#if defined(Q_OS_ANDROID)
this->android->fileChooser();
#endif
}
void Babe::scanDir(const QString &url)
{
emit this->settings->collectionPathChanged({url});
......
......@@ -12,6 +12,7 @@
class Notify;
#elif defined (Q_OS_ANDROID)
class NotificationClient;
class Android;
#endif
class CollectionDB;
......@@ -124,6 +125,7 @@ class Babe : public CollectionDB
Q_INVOKABLE static void sendText(const QString &text);
Q_INVOKABLE static void sendTrack(const QString &url);
Q_INVOKABLE static void openFile(const QString &url);
Q_INVOKABLE void fileChooser();
Q_INVOKABLE static void androidStatusBarColor(const QString &color);
......@@ -138,6 +140,7 @@ class Babe : public CollectionDB
Notify *nof;
#elif defined (Q_OS_ANDROID)
NotificationClient *nof;
Android *android;
#endif
QString fetchCoverArt(DB &song);
......
......@@ -32,7 +32,7 @@ Kirigami.ApplicationWindow {
minimumWidth: !isMobile ? columnWidth : 0
minimumHeight: !isMobile ? columnWidth + 64 : 0
height: 500
title: qsTr("Babe")
title: qsTr("vvave")
// wideScreen: root.width > coverSize
/*ALIASES*/
......
......@@ -126,10 +126,11 @@ BabePopup
iconName: "list-add"
onClicked:
{
if(bae.isMobile())
if(isMobile)
{
folderPicker.open()
folderPicker.load(bae.homeDir())
bae.fileChooser()
// folderPicker.open()
// folderPicker.load(bae.homeDir())
}else
folderDialog.open()
}
......
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