I'm trying to get an image from the gallery of Android
using Qt. I've already called intent
of Java using a arquivo Java
, but I do not know how to return the value to Qt.
I have a class that calls a method in the Java file that opens Android Image Picker
. How can I return the selected image to Qt?
The .h file
#ifndef CAMINHOIMAGENS_H
#define CAMINHOIMAGENS_H
#include <QObject>
#include <QDebug>
class caminhoImagens : public QObject
{
Q_OBJECT
Q_PROPERTY(QString imagemCaminho READ imagemCaminho NOTIFY imagemCaminhoChanged)
slots:
void atualizaImagem();
public:
QString imagemCaminho();
private:
QString m_imagemCaminho = "";
signals:
void imagemCaminhoChanged();
};
#endif // CAMINHOIMAGENS_H
the .cpp file
#include "caminhoimagens.h"
#include <QtAndroidExtras>
caminhoImagens::caminhoImagens()
{
}
void caminhoImagens::atualizaImagem()
{
//org.qtproject.example.acessargaleriatest
QAndroidJniObject intent = QAndroidJniObject::callStaticObjectMethod (
"org/qtproject/example/AcessarGaleriaTest/ImagePickerAndroid",
"imagePicker",
"()Landroid/content/Intent;");
QtAndroid::startActivity(intent, 192837465, 0);
}
QString caminhoImagens::imagemCaminho()
{
return m_imagemCaminho;
}
The .java file
package org.qtproject.example.AcessarGaleriaTest;
import org.qtproject.qt5.android.bindings.QtActivity;
import android.content.Intent;
import android.app.Activity;
public class ImagePickerAndroid extends QtActivity
{
public static Intent imagePicker()
{
Intent i = new Intent(Intent.ACTION_PICK);
i.setType( "image/*");
return Intent.createChooser(i, "Select Image");
}
}