【问题标题】:Android open gallery from folderAndroid从文件夹打开画廊
【发布时间】:2014-08-25 03:56:02
【问题描述】:

我想在 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


【解决方案1】:

试试这个

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 小部件

【讨论】:

  • 相同的结果,它显示了图像,但不会让我在文件夹的其他图像之间滑动:C
  • 只需检查您是否使用了正确的路径。只需使用 Log.e("My Path",path); 打印路径。上面的代码正在运行。希望这对你有帮助:)
  • 路径没问题,它给我展示了图像,不要让我伤心地滑XD
  • 我认为它只是不可能做我想做的事情,就像一些人说这取决于图像查看器对 uri 所做的事情我想我会制作自己的图像查看器,所以我可以做无论我想要什么,我都会让你作为答案 b/c 你链接到它不可能的帖子,所以谢谢你! :D
【解决方案2】:

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

为了显示照片并在其他照片中滑动,我们需要提供的不是文件 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);

}

【讨论】:

    【解决方案3】:

    试试这个方法,希望能帮助你解决问题。

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

    【讨论】:

    • 不,这不行,我已经在文件夹中显示照片的缩略图,我需要全屏打开它们并滑动扔掉它们。还是谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-06
    相关资源
    最近更新 更多