6

選択したすべての画像の画像パスを取得する方法、またはアプリに表示する方法はありますか?ユーザーがギャラリーで画像を選択し、以下に示すように共有ボタンを押すと、暗黙のインテントを開始して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>

しかし、組み込みのギャラリーで複数の画像を選択したいのですが、共有ボタンを押すと、それらすべてをアプリに表示できるはずです。どうすればよいですか?

または、SDカードから選択したすべての画像の画像パスを取得するだけで十分です

4

1 に答える 1

12

私はそれを自分で手に入れました:必要に応じて他の人を助けるかもしれないのでそれを投稿してください

ギャラリーを開いて共有ボタンを選択すると、私のアプリケーションは共有するオプションの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);
}
于 2012-11-22T09:12:16.363 に答える