0

I'm trying to read a photo off the Android device gallery to display in my app.

My app allows a user to select an image from the gallery and this code within an onActivityResult() method saves the filename for later use:

if (resultCode == Activity.RESULT_OK) {
      String[] filePathColumn = {MediaStore.Images.Media.DATA};

      Cursor cursor = getActivity().getContentResolver().query(data.getData(), filePathColumn, null, null, null);
      cursor.moveToFirst();

      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
      String filename = cursor.getString(columnIndex);
      cursor.close();
}

I then later try to display the photo in another activity like so:

  ImageView photoImageView = (ImageView) itemView.findViewById(R.id.photoImageView);
  Uri uri = Uri.fromFile(new File(photoFilename));
  Log.i("AddInformationDialog", "URI found: " + uri);
  photoImageView.setImageURI(uri)

But I'm getting this Permission Denied error:

WARN/ImageView(14618): Unable to open content: file:///mnt/sdcard/dcim/Camera/2012-05-31_09-37-03_660.jpg
    java.io.FileNotFoundException: /mnt/sdcard/dcim/Camera/2012-05-31_09-37-03_660.jpg (Permission denied)
    at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)

I looked at the Manifest permissions and didn't see one that explicitly allowed an app to read from the filesystem. What am I missing?

Thanx in advance.

NLam
  • 537
  • 1
  • 11
  • 25

1 Answers1

0

Rewrite

I couldn't re-create your error, perhaps it is a Droid Bionic specific issue. The only things I can think of are that: the file doesn't allow read access or it has a lock on it preventing the read. Here's a shot in the dark:

  ImageView photoImageView = (ImageView) itemView.findViewById(R.id.photoImageView);
  File file = new File(photoFilename);
  file.setReadable(true);
  Uri uri = Uri.fromFile(file);
  Log.i("AddInformationDialog", "URI found: " + uri);
  photoImageView.setImageURI(uri);
Sam
  • 86,580
  • 20
  • 181
  • 179
  • Do I need WRITE_EXTERNAL_STORAGE when I'm just reading from it? – NLam Jun 01 '12 at 22:58
  • Nope. Sorry, I read your question too fast. I cannot re-create your Permission Denied error and the Apache source code doesn't point anything obvious. Could you provide some more detail? Does this happen with every file or just this one? – Sam Jun 02 '12 at 04:18
  • It happens with every file. I loaded it on a different phone and am now getting a memory error, so it looks like it could be specific to the Droid Bionic I was running on. It at least tried to load the image on a Samsung Captivate. The problem is, my customer needs it to run on the Bionic. – NLam Jun 02 '12 at 17:39
  • I don't have access to a Bionic myself, but I updated my answer. – Sam Jun 02 '12 at 20:07
  • My SonyEriccson does wierd things if it's plugged in. I have to "disconnect" the phone memory card! – user462990 Aug 09 '13 at 15:40