1

I'm trying to make the gallery app share images to my app, the problem is that I don't know how to get the image data sent to me by the gallery. I assumed that I may found the data in the method .getData() but it returns null

this is my intent-filter

<intent-filter>
            <action android:name="android.intent.action.SEND"/>
            <action android:name="android.intent.action.VIEW"/>
            <data android:mimeType="image/*"/>
            <category android:name="android.intent.category.default"/>
        </intent-filter>

and here is my code in MainActivity

Intent data = getIntent(); //get the intent that starts this activity, in this case: gallery intent
    if(data != null){ 
        Uri uri = data.getData();
        //set the image view: the problem is: uri is always null
        imageView.setImageURI(uri);
    }

if the method getData() is not what I want, then how can I get the image that meant to be shared with my app?

Abdullah ALT
  • 106
  • 7
  • are you using startActivityForResult & onActivityResult ? if possible thn post your entire activity code which you have done – user1140237 Nov 16 '15 at 09:33
  • @user1140237 no I don't, isn't it just for startActivityForResult()? I'm not using my app to pick an image from the gallery, all I want is making the gallery **share** images with my app – Abdullah ALT Nov 16 '15 at 09:38
  • Try to use "content" or "file" mimetype. Don't know if it can be done this way but on my device default Gallery app returns "content" uri for pick image intent and file manager app returns "file" uri for the same image. Perhaps this action somehow similar to what you want. Also try to envistigate Intent extras. Maybe image data is bundled within it. – Lingviston Nov 16 '15 at 10:01

1 Answers1

0

So, I think my answer is a little bit late, but anyhow, here it is:

You have already set the intent-filter in the AndroidManifest.xml correct like this:

<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
</intent-filter>

As on this Website stated, you get the URI with this command:

Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);

//set content of ImageView to the specific Uri
imageView.setImageURI(imageUri);

Dokumentation about the Intent class can be found here.

Markus
  • 98
  • 1
  • 7