android:在图库中选择多个图像并启动隐式意图 [英] android:selecting multiple images in gallery and starting implicit intent

查看:88
本文介绍了android:在图库中选择多个图像并启动隐式意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取所有选定图像的图像路径或仅将其显示在我的应用程序中? 当用户选择图库中的图像并按下共享按钮(如下所示)时,我就可以启动隐式意图并将其显示在imageView中

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

我的活动清单文件中

<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?

或者从sdcard获取所有选定图像的图像路径对我来说已经绰绰有余

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

推荐答案

我自己得到的:将其发布,因为它可能会在需要时帮助其他人

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

我们应该告诉android,当我们打开图库并选择共享按钮时,我的应用程序必须是共享选项之一,例如:

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:

清单文件:

<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文件:

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

这篇关于android:在图库中选择多个图像并启动隐式意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆