How can I display a specific folder in Android Gallery3D (cooliris)?

I am using Gallery3D (froyo-stable)

I am trying to create a small application that displays only images from a specific folder as a gallery.

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 a mistake

 "Error finding album " + bucketId); 

In CacheService.loadMediaSets. :

  Log.e(TAG, "Error finding album " + bucketId); 

How can i fix this? Thankyou

+4
source share
2 answers

The problem "Album search error" is most likely due to the fact that in the "DCIM" folder, in which you get the bucketId from your code, there are no images directly in it. You should not get an error if, for example, you use "/ DCIM / Camera" (assuming that there are some images there).

However, if I understand correctly what you want, I believe that there are additional changes that need to be made to the Gallery3D code so that it displays a specific folder at startup if you follow this route (since the code is simply not intended for such use).

Instead of using my code above, I believe that you can achieve what you want easier 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 do here is to use the ACTION_VIEW tag ACTION_VIEW application when it comes with the vnd.android.cursor.dir/image MIME type.

+1
source

Assuming you need to find the file path under the 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. Therefore, to make sure you choose the right path, you can use the code below.

  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); } 

Alternative:

You can also use a 3d carousel to display images using renderscrip as an alternative.

http://code.google.com/p/android-ui-utils/downloads/detail?name=CarouselExample.zip

The final shot. Carousel 3d tested on Bean jelly.

enter image description here

+2
source

Source: https://habr.com/ru/post/1469018/


All Articles