2
I’m trying to get an image from the Android
using Qt. I’ve already called the intent
of Java using a arquivo Java
, But I don’t know how to return the value to Qt.
I have a class that calls a method in the Java file that opens the Android Image Picker
. How can I return the selected image to Qt?
The file . h
#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 file . cpp
#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 file . java
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");
}
}