从画廊的Andr​​oid挑图片画廊、图片、Andr、oid

2023-09-12 00:25:55 作者:慕暖

我要创建画廊的图片选择器。我用code

I want to create a picture chooser from gallery. I use code

 intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
 startActivityForResult(intent, TFRequestCodes.GALLERY);

我的问题是,在这一活动和视频文件被显示。有没有一种方法来过滤显示的文件,所以没有录像文件将被显示在此活动?

My problem is that in this activity and video files are displayed. Is there a way to filter displayed files so that no video files will be displayed in this activity?

推荐答案

当然可以。试试这个:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);

这就是我所说的图片库。穿上它,看看它是否适合你。

That's how I call the image gallery. Put it in and see if it works for you.

编辑:

这将打开文件的应用程序。为了让用户能够同时使用任何画廊的应用程序,他们可能已经安装了:

This brings up the Documents app. To allow the user to also use any gallery apps they might have installed:

    Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
    getIntent.setType("image/*");

    Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    pickIntent.setType("image/*");

    Intent chooserIntent = Intent.createChooser(getIntent, "Select Image");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});

    startActivityForResult(chooserIntent, PICK_IMAGE);