【问题标题】:android:selecting multiple images in gallery and starting implicit intentandroid:在图库中选择多个图像并启动隐式意图
【发布时间】:2012-11-14 11:38:44
【问题描述】:

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

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>

但是我想在内置图库中选择多个图像,当我按下共享按钮时,我应该能够在我的应用程序中显示它们,那么我该怎么做呢?

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

【问题讨论】:

    标签: android android-intent android-gallery intentfilter


    【解决方案1】:

    我自己得到了它:发布它,因为如果需要它可能会帮助其他人

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

    清单文件:

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

    选择我们的应用程序后,它将打开每个图像上带有复选框的图库以选择图像, 在应用程序中处理选定的图像:

    selectedimages.java 文件:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多