[英]Android - How to open a specific folder in a gallery using an implicit intent?
我們正在構建一個相機應用程序,將照片保存在圖庫中的特定文件夾中。 而且,我們必須使用意圖在圖庫中打開應用程序的文件夾。 我們正在使用此代碼,但是它顯示了所有文件夾。
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);
}
};
試試這個代碼。 它將在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);
要打開畫廊,我會使用此意圖。
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 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.