title: Share image from SD Card
body: <p>I'm trying for 2 weeks to find how to share images which are stored on an SD card with no success. </p>
  
  <p>This <a href="https://stackoverflow.com/questions/9018363/android-share-bitmap-not-saved-to-sd">answer</a> doesn't work to me, nor is it what I'm looking for.</p>
  
  <p>I'm working with <em>Cam Preview app</em> that stores images to SD and then display them in in-app gallery: </p>
  
  <pre><code>   public class GalleryView extends Activity {  
  
     private static final int SELECT_PICTURE = 1;
  
  private String selectedImagePath;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.gallery_view);
  
      Gallery g = (Gallery) findViewById(R.id.gallery);
      g.setAdapter(new ImageAdapter(this, ReadSDCard()));
  
  
      g.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) {
      Intent intent = new Intent();
              intent.setType("image/*");
              intent.setAction(Intent.ACTION_GET_CONTENT);
              startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
          }
      });
  }
  
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (resultCode == RESULT_OK) {
          if (requestCode == SELECT_PICTURE) {
              Uri selectedImageUri = data.getData();
              selectedImagePath = getPath(selectedImageUri);
  
              Intent shareIntent = new Intent();
              shareIntent.setAction(Intent.ACTION_SEND);
              shareIntent.putExtra(Intent.EXTRA_STREAM, selectedImagePath);
              shareIntent.setType("image/*");
              startActivity(Intent.createChooser(shareIntent, "Share image"));
          }
      }
  }
  
  public String getPath(Uri uri) {
      String[] projection = { MediaStore.Images.Media.DATA };
      Cursor cursor = managedQuery(uri, projection, null, null, null);
      int column_index = cursor
              .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      cursor.moveToFirst();
      return cursor.getString(column_index);
  }
  
  @Override
  public void onDestroy() {
      super.onDestroy();       
  }
  
  private List&lt;String&gt; ReadSDCard() {
  
      createDirIfNotExists();
  
      List&lt;String&gt; tFileList = new ArrayList&lt;String&gt;();
  
      //It have to be matched with the directory in SDCard
      File f = new File("/sdcard/Cam App");
  
      File[] files=f.listFiles();
  
      for(int i=0; i&lt;files.length; i++) {
          File file = files[i];
          /*It's assumed that all file in the path are in supported type*/
          tFileList.add(file.getPath());
      }
  
      return tFileList;
  }
  
  class ViewHolder {
      ImageView i;
  }
  
  public class ImageAdapter extends BaseAdapter {
      int mGalleryItemBackground;
      private Context mContext;
      private List&lt;String&gt; FileList;
      LayoutInflater inflater = getLayoutInflater();
      ViewHolder holder;
  
      public ImageAdapter(Context c, List&lt;String&gt; fList) {
          mContext = c;
          FileList = fList;
          TypedArray a = obtainStyledAttributes(R.styleable.GalleryTheme);
          mGalleryItemBackground = a.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
          a.recycle();
      }
  
      public int getCount() {
          return FileList.size();
      }
  
      public Object getItem(int position) {
          return position;
      } 
  
      public long getItemId(int position) {
          return position;
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
          ImageView i = new ImageView(mContext);
  
          Bitmap bm = BitmapFactory.decodeFile(FileList.get(position).toString());
          i.setImageBitmap(bm);
  
          if (convertView == null) {
              convertView = inflater.inflate(R.layout.gallery_item, parent, false);
  
              holder = new ViewHolder();
              holder.i = ((ImageView) convertView.findViewById(R.id.imagenGallery));
  
              convertView.setTag(holder);
          }
          holder.i.setScaleType(ImageView.ScaleType.FIT_XY);
          holder.i.setBackgroundResource(mGalleryItemBackground);
  
          return i;
      }
  }
  
  public TypedArray obtainStyledAttributes(int theme) {
      // TODO Auto-generated method stub
      return null;
  }
  }
  </code></pre>
  
  <p>The gallery works fine, but I don't get how to share the images saved on the SD. </p>
  
  <p>How to access that images in <em>Cam App folder</em> and share the image that appears in that moment in the gallery? </p>
  
  <p>I tried to use positions, but it only works with constant images. Any help/tips would be appreciated.</p>