I'm using Gallery3D (froyo-stable)
I'm trying to make a little app that displays only images from a specific folder in a gallery view.
Uri targetUri = Media.EXTERNAL_CONTENT_URI;
String folderPath = Environment.getExternalStorageDirectory().toString() + "/DCIM/";
int folderBucketId = folderPath.toLowerCase().hashCode();
targetUri = targetUri.buildUpon().appendQueryParameter("bucketId", String.valueOf(folderBucketId)).build();
In initializeDataSource()
// Creating the DataSource objects.
final LocalDataSource localDataSource = new LocalDataSource(Gallery.this, targetUri.toString(), false);
But I have error
"Error finding album " + bucketId);
In CacheService.loadMediaSets.
:
Log.e(TAG, "Error finding album " + bucketId);
How can I fix this?
Thankyou
The "Error finding album" issue is most likely due to the fact that the "DCIM" folder that you get the bucketId
from in your code does not have any images directly in it. You should not get the error if for example you use "/DCIM/Camera" instead (assuming there are some images there).
However, if I understand correctly what you want, I believe there are additional modifications that you need to make on the Gallery3D code in order to make it display a specific folder when launched if you follow this route (since the code is just not designed to be used like that).
Instead of using your code above, I believe you can achieve what you want more easily by setting the intent to a specific one in onCreate()
:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setIntentToSpecificFolder();
mApp = new App(Gallery.this);
// :
// the rest of onCreate() code
// :
Log.i(TAG, "onCreate");
}
private void setIntentToSpecificFolder() {
String folderPath = Environment.getExternalStorageDirectory().toString() + "/DCIM/Camera";
int folderBucketId = folderPath.toLowerCase().hashCode();
Uri targetUri = Media.EXTERNAL_CONTENT_URI.buildUpon().appendQueryParameter("bucketId", String.valueOf(folderBucketId)).build();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "vnd.android.cursor.dir/image");
setIntent(intent);
}
Basically what we are doing here is leveraging the ACTION_VIEW
intent handling of the app when it is supplied with a vnd.android.cursor.dir/image
MIME type.
Assuming you need to find path of files under a folder.
private String[] mFileStrings;
private File[] listFile;
public void getFromSdcard()
{
File file= new File(android.os.Environment.getExternalStorageDirectory(),"Your Folder Name");
if (file.isDirectory())
{
listFile = file.listFiles();
mFileStrings = new String[listFile.length];
for (int i = 0; i < listFile.length; i++)
{
mFileStrings[i] = listFile[i].getAbsolutePath();
System.out.println("...................................."+mFileStrings[i]);
}
}
}
In my phone my internal memory was named sdcard0. So to make sure you get the path of the right one you can use the below code.
String externalpath = new String();
String internalpath = new String();
public void getExternalMounts() {
Runtime runtime = Runtime.getRuntime();
try
{
Process proc = runtime.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line;
BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
if (line.contains("secure")) continue;
if (line.contains("asec")) continue;
if (line.contains("fat")) {//external card
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
externalpath = externalpath.concat("*" + columns[1] + "\n");
}
}
else if (line.contains("fuse")) {//internal storage
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
internalpath = internalpath.concat(columns[1] + "\n");
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Path of sd card external............"+externalpath);
System.out.println("Path of internal memory............"+internalpath);
}
An Alternative:
Also you can use 3d carousel to display images using renderscrip as an alternative.
http://code.google.com/p/android-ui-utils/downloads/detail?name=CarouselExample.zip.
Resulting snapshot. Carousel 3d tested on Jelly Bean.