来自文件夹的Android打开画廊

问题描述 投票:4回答:3

我想在android相册中显示照片,并能够将其他照片滑动扔到该文件夹​​中。

Intent intent = new Intent(Intent.ACTION_VIEW);
File f = new File(path);
intent.setDataAndType(Uri.parse("file://" + f.getAbsolutePath()), "image/*");
mContext.startActivity(intent);

这就是我现在的做法,但是不会让我滑动将其余图像丢到文件夹中。我尝试过:

How to open one particular folder from gallery in android?

Built-in gallery in specific folder

Gallery with folder filter

没有任何运气。如果有人有解决方案,我将非常高兴。谢谢!

android android-intent android-image android-gallery
3个回答
10
投票

尝试一下

Intent i=new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(new File(path)), "image/*");  
startActivity(i);

查看这些链接

How can I use Intent.ACTION_VIEW to view the contents of a folder?

Android ACTION_VIEW Multiple Images

Java and Android: How to open several files with an Intent?

如果这解决了您的问题。另请检查

https://www.google.co.in/?gfe_rd=cr&ei=c5n9U6ruE7DO8gfXz4G4BA&gws_rd=ssl#q=view+like+gallery

还要检查Gallery小部件


0
投票

尝试这种方式,希望它可以帮助您解决问题。

final int OPEN_GALLERY = 1
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, ""), OPEN_GALLERY);

0
投票

这个问题来自五年前,但是我想提供一个对我有用的答案,而不是正确的答案。

为了显示照片并浏览其他照片,我们需要使意图不是文件uri,而是媒体uri。

public void ShowPhoto(File imageFile) {

    String mediaId = "";

    String[] projection = new String[] {
            MediaStore.Images.Media._ID,
            MediaStore.Images.Media.DISPLAY_NAME
    };

    Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection, null, null, null);

    while (cursor != null && cursor.moveToNext()) {
        String name = cursor.getString((cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME)));
        if(name.equals(imageFile.getName())){
            mediaId = cursor.getString((cursor.getColumnIndex(MediaStore.Images.ImageColumns._ID)));
            break;
        }
    }

    Uri mediaUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

    if(!mediaId.equals("")){
        mediaUri = mediaUri.buildUpon()
                .authority("media")
                .appendPath(mediaId)
                .build();
    }

    Log.d("TagInfo","Uri:  "+mediaUri);

    Intent intent = new Intent(Intent.ACTION_VIEW, mediaUri);
    startActivity(intent);

}
© www.soinside.com 2019 - 2024. All rights reserved.