5

I'm trying to view the images in a specific folder using an intent. My code is as follows:

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_VIEW);  
Uri imgUri = Uri.parse("file://sdcard/download");  
intent.setDataAndType(imgUri, "image/*");  
startActivity(intent);  

However, each time it runs, I get this message in the log:

02-25 00:40:16.271: ERROR/(8359): can't open '/download'
02-25 00:40:16.271: ERROR/(8359): can't open '/download'

What am I doing wrong?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Jevarlo
  • 51
  • 1
  • 1
  • 2
  • Do you have access to the SDCard? – Mudassir Feb 25 '11 at 06:51
  • This is completely unrelated to the question, but does anyone else not see edit/retag links for this question? Am I missing something as to why they're not there? – Andrew Marshall Feb 25 '11 at 06:54
  • Mudassir, I do have access to the sdcard, I tested this by creating a simple text file on it. – Jevarlo Feb 25 '11 at 08:07
  • Have you tried to add additional slash to URI: `"file:///sdcard/download"`? – Michael Feb 25 '11 at 08:14
  • I just tried that and got a bit farther! except now i get a different error! Adding an extra slash to my URI gets me this error: 02-25 07:37:29.106: ERROR/(10632): Not JPEG: /sdcard/download/ And even adding a wildcard to the end of the URI so it looks like this "file:///sdcard/download/*" doesn't resolve it. – Jevarlo Feb 25 '11 at 13:40
  • With that Intent it tries to find an application to open the file "file://sdcard/download". Which is not a file, but a folder. You will need a different Intent. – RvdK Dec 18 '12 at 11:05

4 Answers4

1

I think this is far simpler than everyone else is suggesting. I believe the path is case sensitive. In your example "file://sdcard/Download" should work.

1

try something like this

Intent intent = new Intent();
intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);

or

Intent intent = new Intent();
intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);
OWADVL
  • 10,704
  • 7
  • 55
  • 67
0

I had a similar problem a while back where I had an instance that required me to give the user the option to select a photo from a predetermined location. The working solution for this that I am currently using requires that you have some kind of file manger already on the device. The one that I am using is called "OI File Manager". It's free to download from the Android/Play market. With that being said you could try using:

 //--Note: You can supply the full location of the folder but if you don't know it and
//         if the folder location is on the sdcard, provide the following:
 File root = new File(Environment.getExternalStorageDirectory() + File.separator + "myFolder" + File.separator);
 Uri uri = Uri.fromFile(root);

 Intent intent = new Intent();
 intent.setAction(android.content.Intent.ACTION_VIEW);
 intent.setData(Uri.fromFile(root));
 startActivityForResult(intent, PIC_REQUEST);

What this will do is open a dialog asking for you to select an option to use to process the request. When it does that just check the box in the bottom corner "Use by default..." before selecting the "OI File Manager" option. This will set it so that each time the intent is launched it will automatically open your specified location so that you can view the contents without having to drill down to the folder location every time when the intent is launched. It's not good to have to rely on a third party app but it could be a option for you.

cking24343
  • 3,173
  • 1
  • 21
  • 23
0
Intent intent = new Intent();  
intent.setAction(Intent.ACTION_GET_CONTENT);
Uri imgUri = Uri.fromFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
intent.setDataAndType(imgUri, "file/*");   
startActivity(intent);

works for me..

thinzar00
  • 588
  • 2
  • 5
  • 13