2015-11-01 67 views
0

我們正在構建一個照相機應用程序,將照片保存在圖庫中的特定文件夾中。我們必須使用意圖在庫中打開我們的應用程序的文件夾。我們正在使用此代碼,但它顯示所有文件夾。Android - 如何使用隱式意圖在庫中打開特定的文件夾?

View.OnClickListener goToGallery = new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     Intent intent = new Intent(); 
     intent.setAction(android.content.Intent.ACTION_VIEW); 
     intent.setType("image/*"); 
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     startActivity(intent); 
    } 
}; 
+0

可能重複[如何顯示Android圖庫上的特定文件夾的圖像](http://stackoverflow.com/questions/13418807/how-can-i-display-images-from-a- specific-folder-on-android-gallery) – Mohamed

回答

0

要打開圖庫我使用這個意圖。

public static final int RESULT_GALLERY = 0; 

Intent galleryIntent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

startActivityForResult(galleryIntent , RESULT_GALLERY);

+0

感謝您的回答。然而,我們不需要選擇一張照片,我們只需要查看我們在圖庫中的文件夾中的照片:) – giroxasmnl

+0

我不完全確定,但嘗試用ACTION_VIEW替換ACTION_PICK爲我的上述代碼。 –

0

試試這個代碼。 它將根據storage/emulated/0/Pictures/MyAppPics 檢索視圖圖片您可以根據您的目錄路徑更改文件路徑。

File sdDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 
File f = new File(sdDir, "MyAppPics"); 

Intent i = new Intent(); 
i.setAction(Intent.ACTION_VIEW); 
i.setDataAndType(Uri.withAppendedPath(Uri.fromFile(f), "/MyAppPics"), "image/*"); 
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(i); 
+0

要使用此功能,是否必須在存儲/模擬/ 0 /圖片中包含圖像?我的圖像位於內存中的文件夾中。而這個解決方案不適合它。 –

相關問題