title: Qt and Android - Get path from image in gallery
body: <p>I have done a code to get an image from <code>Android gallery</code>. I am using <code>QtAndroid</code> to write a equivalent java code in Qt.</p>
  
  <p>I have already opened the gallery, selected the image and received the path, but it returns the <code>MediaColumn</code> of the file and I need the absolute path.</p>
  
  <p>How can I get the absolute path of the file using <code>QAndroid</code> to write a Java equivalent code in Qt?</p>
  
  <p>Here is the code I have done:</p>
  
  <p>imagepickerandroid.h</p>
  
  <pre><code>#ifndef IMAGEPICKERANDROID_H
  #define IMAGEPICKERANDROID_H
  
  
  #include &lt;QObject&gt;
  #include &lt;QtAndroidExtras&gt;
  
  #include &lt;QDebug&gt;
  
  class imagePickerAndroid : public QObject, public QAndroidActivityResultReceiver
  {
      Q_OBJECT
  
  public:
      imagePickerAndroid();
  
      void buscaImagem();
  
      virtual void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &amp; data);
  
  signals:
      void imagemCaminhoSignal(QString);
  };
  
  #endif // IMAGEPICKERANDROID_H
  </code></pre>
  
  <p>imagepickerandroid.cpp</p>
  
  <pre><code>#include "imagepickerandroid.h"
  
  imagePickerAndroid::imagePickerAndroid()
  {
  
  }
  
  void imagePickerAndroid::buscaImagem()
  {
      QAndroidJniObject ACTION_PICK = QAndroidJniObject::fromString("android.intent.action.GET_CONTENT");
      QAndroidJniObject intent("android/content/Intent");
      if (ACTION_PICK.isValid() &amp;&amp; intent.isValid())
      {
          intent.callObjectMethod("setAction", "(Ljava/lang/String;)Landroid/content/Intent;", ACTION_PICK.object&lt;jstring&gt;());
          intent.callObjectMethod("setType", "(Ljava/lang/String;)Landroid/content/Intent;", QAndroidJniObject::fromString("image/*").object&lt;jstring&gt;());
          QtAndroid::startActivity(intent.object&lt;jobject&gt;(), 101, this);
          qDebug() &lt;&lt; "OK";
      }
      else
      {
          qDebug() &lt;&lt; "ERRO";
      }
  }
  
  void imagePickerAndroid::handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &amp;data)
  {
      qDebug() &lt;&lt; "Trabalha com os dados";
  
      jint RESULT_OK = QAndroidJniObject::getStaticField&lt;jint&gt;("android/app/Activity", "RESULT_OK");
      if (receiverRequestCode == 101 &amp;&amp; resultCode == RESULT_OK) {
          QString imagemCaminho = data.callObjectMethod("getData", "()Landroid/net/Uri;").callObjectMethod("getPath", "()Ljava/lang/String;").toString();
          emit imagemCaminhoSignal(imagemCaminho);
  
          qDebug() &lt;&lt; imagemCaminho;
      }
      else
      {
          qDebug() &lt;&lt; "Caminho errado";
      }
  }
  </code></pre>