android:selecting multiple images in gallery and starting implicit intent

淺唱寂寞╮ 提交于 2019-12-12 09:39:09

问题


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


回答1:


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);
}


来源:https://stackoverflow.com/questions/13378108/androidselecting-multiple-images-in-gallery-and-starting-implicit-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!