Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving an ACTION_SEND intent from the Gallery

Tags:

android

I am trying to receive an image from the Android Gallery via an ACTION_SEND intent. I have set the proper intent filters and the Gallery opens my app. Now I want to know how to get at the image data. I can't find any examples on the internet of how this is done. I figure the path is somewhere in intent.getData() but how exactly do I pull that image from the gallery?

like image 957
KyleStew Avatar asked Apr 13 '10 20:04

KyleStew


1 Answers

Found this in the Picasa source. It gives the proper path of the image.

    Intent intent = getIntent();
    if (Intent.ACTION_SEND.equals(intent.getAction())) {
        Bundle extras = intent.getExtras();
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            String scheme = uri.getScheme();
            if (scheme.equals("content")) {
                String mimeType = intent.getType();
                ContentResolver contentResolver = getContentResolver();
                Cursor cursor = contentResolver.query(uri, null, null, null, null);
                cursor.moveToFirst();
                String filePath = cursor.getString(cursor.getColumnIndexOrThrow(Images.Media.DATA));
like image 128
KyleStew Avatar answered Oct 26 '22 23:10

KyleStew