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.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) 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 #ifndef ANDROID_H
#define ANDROID_H #define ANDROID_H
#include <QAndroidActivityResultReceiver>
#include <QObject> #include <QObject>
#include <QAndroidJniObject>
#include <QAndroidJniEnvironment>
#include <QtAndroid>
class Android : public QObject class Android : public QObject, public QAndroidActivityResultReceiver
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Android(QObject *parent = nullptr); explicit Android(QObject *parent = nullptr);
Q_INVOKABLE void fileChooser();
virtual void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject & data);
private:
QAndroidActivityResultReceiver *resultReceiver;
signals: signals:
void folderPicked(const QString &url);
public slots: public slots:
}; };
#endif // ANDROID_H #endif // ANDROID_H
\ No newline at end of file
...@@ -10,6 +10,8 @@ import java.io.File; ...@@ -10,6 +10,8 @@ import java.io.File;
public class SendIntent public class SendIntent
{ {
private static final int READ_REQUEST_CODE = 42;
public static void sendText(Activity context,String text) public static void sendText(Activity context,String text)
{ {
Intent sendIntent = new Intent(); Intent sendIntent = new Intent();
...@@ -53,12 +55,14 @@ public class SendIntent ...@@ -53,12 +55,14 @@ public class SendIntent
intent.setDataAndType(uri, mime); intent.setDataAndType(uri, mime);
context.startActivity(Intent.createChooser(intent, "Open folder")); 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 @@ ...@@ -25,6 +25,7 @@
#if defined(Q_OS_ANDROID) #if defined(Q_OS_ANDROID)
#include "android/notificationclient.h" #include "android/notificationclient.h"
#include "android/android.h"
#include <QAndroidJniObject> #include <QAndroidJniObject>
#include <QAndroidJniEnvironment> #include <QAndroidJniEnvironment>
#include <QtAndroid> #include <QtAndroid>
...@@ -96,6 +97,12 @@ Babe::Babe(QObject *parent) : CollectionDB(parent) ...@@ -96,6 +97,12 @@ Babe::Babe(QObject *parent) : CollectionDB(parent)
}); });
#elif defined (Q_OS_ANDROID) #elif defined (Q_OS_ANDROID)
this->nof = new NotificationClient(this); this->nof = new NotificationClient(this);
this->android = new Android(this);
connect(android, &Android::folderPicked, [this](const QString &url)
{
qDebug()<< "Folder picked"<< url;
});
#endif #endif
} }
...@@ -427,6 +434,14 @@ void Babe::openFile(const QString &url) ...@@ -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) void Babe::scanDir(const QString &url)
{ {
emit this->settings->collectionPathChanged({url}); emit this->settings->collectionPathChanged({url});
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
class Notify; class Notify;
#elif defined (Q_OS_ANDROID) #elif defined (Q_OS_ANDROID)
class NotificationClient; class NotificationClient;
class Android;
#endif #endif
class CollectionDB; class CollectionDB;
...@@ -124,6 +125,7 @@ class Babe : public CollectionDB ...@@ -124,6 +125,7 @@ class Babe : public CollectionDB
Q_INVOKABLE static void sendText(const QString &text); Q_INVOKABLE static void sendText(const QString &text);
Q_INVOKABLE static void sendTrack(const QString &url); Q_INVOKABLE static void sendTrack(const QString &url);
Q_INVOKABLE static void openFile(const QString &url); Q_INVOKABLE static void openFile(const QString &url);
Q_INVOKABLE void fileChooser();
Q_INVOKABLE static void androidStatusBarColor(const QString &color); Q_INVOKABLE static void androidStatusBarColor(const QString &color);
...@@ -138,6 +140,7 @@ class Babe : public CollectionDB ...@@ -138,6 +140,7 @@ class Babe : public CollectionDB
Notify *nof; Notify *nof;
#elif defined (Q_OS_ANDROID) #elif defined (Q_OS_ANDROID)
NotificationClient *nof; NotificationClient *nof;
Android *android;
#endif #endif
QString fetchCoverArt(DB &song); QString fetchCoverArt(DB &song);
......
...@@ -32,7 +32,7 @@ Kirigami.ApplicationWindow { ...@@ -32,7 +32,7 @@ Kirigami.ApplicationWindow {
minimumWidth: !isMobile ? columnWidth : 0 minimumWidth: !isMobile ? columnWidth : 0
minimumHeight: !isMobile ? columnWidth + 64 : 0 minimumHeight: !isMobile ? columnWidth + 64 : 0
height: 500 height: 500
title: qsTr("Babe") title: qsTr("vvave")
// wideScreen: root.width > coverSize // wideScreen: root.width > coverSize
/*ALIASES*/ /*ALIASES*/
......
...@@ -126,10 +126,11 @@ BabePopup ...@@ -126,10 +126,11 @@ BabePopup
iconName: "list-add" iconName: "list-add"
onClicked: onClicked:
{ {
if(bae.isMobile()) if(isMobile)
{ {
folderPicker.open() bae.fileChooser()
folderPicker.load(bae.homeDir()) // folderPicker.open()
// folderPicker.load(bae.homeDir())
}else }else
folderDialog.open() 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