title: How to pick images from SD card gallery and not other sources
body: <p>I'm creating an app that lets users pick a picture from the phone gallery. All works fine for images on the SD card but when the user selects a picture from Picassa, the application crashes.</p>
  
  <p>Code for calling gallery:</p>
  
  <pre><code>Intent i = new Intent(Intent.ACTION_PICK,
     android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  startActivityForResult(i, SELECT_FROM_GALLERY_ACTION);              
  </code></pre>
  
  <p>Code for receiving image:</p>
  
  <pre><code>Uri selectedImage = data.getData();
  String[] filePathColumn = {MediaStore.Images.Media.DATA};
  Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
  cursor.moveToFirst();
  int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
  String filePath = cursor.getString(columnIndex);
  cursor.close();
  File galeryFile = new File(filePath);
  FileUtils.copyFile(galeryFile, imageFile);
  processImage(imageFile);
  </code></pre>
  
  <p>Errror:</p>
  
  <pre><code>08-30 14:51:04.268: E/ActivityThread(31379): Failed to find provider info for com.android.gallery3d.provider
  08-30 14:51:04.278: E/AndroidRuntime(31379): FATAL EXCEPTION: main
  08-30 14:51:04.278: E/AndroidRuntime(31379): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=4353, result=-1, data=Intent { dat=content://com.android.gallery3d.provider/picasa/item/5735585761449205042 flg=0x1 }} to activity {com.example.my_gallery_app/com.example.my_gallery_app.MainActivity}: java.lang.NullPointerException
  </code></pre>
  
  <p>Null pointer occures on line:</p>
  
  <pre><code>cursor.moveToFirst();
  </code></pre>
  
  <p><a href="http://jimmi1977.blogspot.hu/2012/01/android-api-quirks-getting-image-from.html" rel="nofollow">I read this workaround.</a> But comments aren't promising. I would like to restrict gallery from showing the user Facebook, Picassa or other pictures and let her pick images only from the SD card.</p>