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?
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.
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);
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.
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..