ฉันจะแสดงโฟลเดอร์เฉพาะใน Android Gallery3D (cooliris) ได้อย่างไร

ฉันใช้ Gallery3D (froyo-stable)

ฉันกำลังพยายามสร้างแอปเล็กๆ ที่แสดงเฉพาะรูปภาพจากโฟลเดอร์เฉพาะในมุมมองแกลเลอรี

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

แต่ฉันมีข้อผิดพลาด

"Error finding album " + bucketId);

In CacheService.loadMediaSets.:

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

ฉันจะแก้ไขปัญหานี้ได้อย่างไร? ขอบคุณ


person Nam Vu    schedule 13.03.2013    source แหล่งที่มา
comment
คุณต้องการเส้นทางของโฟลเดอร์ใดโฟลเดอร์หนึ่งและดึงภาพจากโฟลเดอร์นั้นหรือไม่?   -  person Raghunandan    schedule 23.03.2013
comment
ใช่ แสดงภาพทั้งหมดจากโฟลเดอร์เดียวเท่านั้น   -  person Nam Vu    schedule 23.03.2013
comment
ฉันไม่รู้เกี่ยวกับ gallery 3d ฉันใช้ 3d carosel โดยใช้ renderscript แต่คุณต้องการโค้ดเพื่อแยกเส้นทางรูปภาพจากโฟลเดอร์เดียวหรือไม่โดยสมมติว่าโฟลเดอร์นั้นมีเพียงรูปภาพเท่านั้น   -  person Raghunandan    schedule 23.03.2013
comment
สมมติว่าคุณต้องแตกพาธของไฟล์ใต้โฟลเดอร์ คุณสามารถใช้โค้ดด้านล่างได้ คุณยังสามารถพิจารณาใช้ carousel 3d โดยใช้ renderscript ได้อีกด้วย   -  person Raghunandan    schedule 24.03.2013
comment
Raghunandan: ขอบคุณสำหรับความคิดเห็นของคุณ แต่สิ่งที่ฉันต้องการคือคำตอบของ @ Joe   -  person Nam Vu    schedule 24.03.2013


คำตอบ (2)


ปัญหา "ข้อผิดพลาดในการค้นหาอัลบั้ม" มักเกิดจากการที่โฟลเดอร์ "DCIM" ที่คุณได้รับ bucketId จากโค้ดของคุณไม่มีรูปภาพใดๆ อยู่ในนั้นโดยตรง คุณไม่ควรได้รับข้อผิดพลาด เช่น หากคุณใช้ "/DCIM/Camera" แทน (สมมติว่ามีภาพบางภาพอยู่ที่นั่น)

อย่างไรก็ตาม หากฉันเข้าใจอย่างถูกต้องว่าคุณต้องการอะไร ฉันเชื่อว่ามีการแก้ไขเพิ่มเติมที่คุณต้องทำในโค้ด Gallery3D เพื่อให้แสดงโฟลเดอร์เฉพาะเมื่อเปิดใช้งานหากคุณทำตามเส้นทางนี้ (เนื่องจากโค้ดไม่ได้ออกแบบมาเพื่อ ให้ใช้แบบนั้น)

แทนที่จะใช้โค้ดของคุณด้านบน ฉันเชื่อว่าคุณสามารถบรรลุสิ่งที่คุณต้องการได้ง่ายขึ้นโดยการกำหนดเจตนาให้เป็นโค้ดเฉพาะใน 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);
}

โดยพื้นฐานแล้วสิ่งที่เรากำลังทำที่นี่คือใช้ประโยชน์จากการจัดการเจตนา ACTION_VIEW ของแอปเมื่อมาพร้อมกับประเภท vnd.android.cursor.dir/image MIME

person Joe    schedule 24.03.2013
comment
ขอบคุณ ฉันจะใช้ getContentUri ใน API ระดับ 8 หรืออะไรทำนองนั้นได้อย่างไร - person Nam Vu; 24.03.2013
comment
ฉันสามารถใช้ Images.Media.EXTERNAL_CONTENT_URI แทนสิ่งนี้ได้หรือไม่ - person Nam Vu; 24.03.2013
comment
ใช่ มันควรจะได้ผลเช่นกัน ฉันแก้ไขคำตอบเพื่อใช้แทน - person Joe; 24.03.2013
comment
โซลูชันนี้ใช้งานได้ดีสำหรับการแสดงอัลบั้มเมื่อใช้แอป Android Gallery แต่จะทำให้แอป Photos ของ Google ขัดข้อง มีอะไรที่สามารถทำได้เพื่อให้ทั้งสองอย่างได้ผลหรือไม่? - person Hostile; 16.08.2014

สมมติว่าคุณต้องการค้นหาเส้นทางของไฟล์ภายใต้โฟลเดอร์

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

ในโทรศัพท์ของฉัน หน่วยความจำภายในของฉันชื่อ sdcard0 ดังนั้นเพื่อให้แน่ใจว่าคุณได้รับเส้นทางที่ถูกต้อง คุณสามารถใช้โค้ดด้านล่างนี้

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

ทางเลือก:

นอกจากนี้คุณยังสามารถใช้ 3d carousel เพื่อแสดงภาพโดยใช้ renderscrip เป็นทางเลือกได้อีกด้วย

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

ภาพรวมผลลัพธ์ Carousel 3d ทดสอบกับ Jelly Bean

ป้อนคำอธิบายรูปภาพที่นี่

person Raghunandan    schedule 24.03.2013