简体   繁体   English

Android-如何使用隐式意图在图库中打开特定文件夹?

[英]Android - How to open a specific folder in a gallery using an implicit intent?

We are building a camera app that saves photos in a specific folder in the gallery. 我们正在构建一个相机应用程序,将照片保存在图库中的特定文件夹中。 And we have to open the folder of our app in the gallery using an intent. 而且,我们必须使用意图在图库中打开应用程序的文件夹。 We are using this code however it shows all folders. 我们正在使用此代码,但是它显示了所有文件夹。

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

Try this code. 试试这个代码。 It will retrieve view pictures under storage/emulated/0/Pictures/MyAppPics You can change the file path according to your directory path. 它将在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);

To open gallery I use this intent. 要打开画廊,我会使用此意图。

public static final int RESULT_GALLERY = 0;

Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM