Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:selecting multiple images in gallery and starting implicit intent

How to get the image path of all the selected images or just display them in my app? I am able to start my implicit intent and display it in my imageView when a user selects image in gallery and press share button like shown below

ImageView iv=(ImageView)findViewById(R.id.im);
iv.setImageUri((Uri)getIntent().getExtras().get(Intent.EXTRA_STREAM));

in manifest file for my activity

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

But i want to select multiple images in inbuilt gallery and when i press share button then i should be able to display them all in my app,so how do i do that?

or getting the image path of all selected images from sdcard would be more than sufficient for me

like image 790
Mahantesh M Ambi Avatar asked Nov 14 '12 11:11

Mahantesh M Ambi


1 Answers

I got it myself:posting it as it might help others if required

we should tell android that when we open gallery and select share button then my application must be one of the option to share,like:

manifestfile:

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

and after selecting our application it will open gallery with check box on each image to select images, Handling selected images in application:

selectedimages.java file:

if (Intent.ACTION_SEND_MULTIPLE.equals(getIntent().getAction())
    && getIntent().hasExtra(Intent.EXTRA_STREAM)) {
    ArrayList<Parcelable> list =
            getIntent().getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                for (Parcelable parcel : list) {
                   Uri uri = (Uri) parcel;
                   String sourcepath=getPath(uri);

                   /// do things here with each image source path.
               }
                finish();
}
}

public  String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
startManagingCursor(cursor);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
like image 54
Mahantesh M Ambi Avatar answered Sep 29 '22 11:09

Mahantesh M Ambi