android:selecting multiple images in gallery and starting implicit intent

时光总嘲笑我的痴心妄想 提交于 2019-12-05 05:58:28

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