Android 如何在图库中多选择图像并将其URL发送到我的活动?

Android 如何在图库中多选择图像并将其URL发送到我的活动?,android,Android,如何在图库中多选择图像并将其URL发送到我的活动? 在多媒体资料中,我已将我的项目添加到“共享”菜单中。但我只能分享 一张图片,让我的活动开始。这段代码为我提供了一个图像的URL。 是否可以设置“多媒体资料”或“共享”菜单,以便用户可以 选择一张或多张图片 if (Intent.ACTION_SEND.equals(action)) { if extras.containsKey(Intent.EXTRA_STREAM)) { Uri uri = (Uri)extras

如何在图库中多选择图像并将其URL发送到我的活动? 在多媒体资料中,我已将我的项目添加到“共享”菜单中。但我只能分享 一张图片,让我的活动开始。这段代码为我提供了一个图像的URL。 是否可以设置“多媒体资料”或“共享”菜单,以便用户可以 选择一张或多张图片

if (Intent.ACTION_SEND.equals(action)) 
 { 
  if extras.containsKey(Intent.EXTRA_STREAM)) 
  { 
    Uri uri = (Uri)extras.getParcelable(Intent.EXTRA_STREAM); //path to image
   Toast toast = Toast.makeText(this, "path: "+     getRealPathFromURI(uri), 
   Toast.LENGTH_SHORT); toast.show(); 
   return; 
} else if 
(extras.containsKey(Intent.EXTRA_TEXT)) { 
    } 

} 
  public String getRealPathFromURI(Uri contentUri) { String[] proj = { 
  MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(contentUri, 
  proj, null, null, null); int column_index = 
  cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
  cursor.moveToFirst(); return cursor.getString(column_index);
}

刚刚从group/android开发者那里得到了这个问题的答案。 谢谢你,布鲁斯

你想要的是多个动作。您将收到一套 URI

比如:

  if (Intent.ACTION_SEND_MULTIPLE.equals(action))
  && Intent.hasExtra(Intent.EXTRA_STREAM)) {
  ArrayList<Parcelable> list =
 intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
 for (Parcelable p : list) {
   Uri uri = (Uri) p;
   /// do something with it.
 }
}
if(Intent.ACTION\u SEND\u MULTIPLE.equals(ACTION))
&&Intent.hasExtra(Intent.EXTRA_流)){
数组列表=
getParcelableArrayListExtra(intent.EXTRA_流);
用于(包裹p:列表){
Uri=(Uri)p;
///用它做点什么。
}
}
只需将android.intent.action.SEND\u MULTIPLE添加到您的清单中


Bruce

我如何将此代码用于我的应用程序。当我单击按钮时,内置图库将打开,我可以从图库中选择多个图像。请建议我你能提到谷歌集团网址来查看原始答案吗?这是原始答案,请检查我从你的代码中得到错误,你能向我解释一下什么是“行动”吗?