开发者

How do i multiselect images in the Gallery and send there URL to my activity?

How do i multiselect images in the Gallery and send there URL to my activity? In the gallery I have added my Item to the share menu. But i can only share one image and making my Activity start. This code give me the URL for one image. Is it possible to set up the Gallery or the share menu so that user can select one or many pictures?

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 = managedQue开发者_Python百科ry(contentUri, 
  proj, null, null, null); int column_index = 
  cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
  cursor.moveToFirst(); return cursor.getString(column_index);
}


Just got an answer to the question from group/android-developers. Thanks Bruce!

What you want is ACTION_SEND_MULTIPLE. You will receive a set of Uris.

Something like:

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

Just add android.intent.action.SEND_MULTIPLE to your manifest.

Bruce

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜