Android 在图库中打开图像并滑动浏览图像

Android open image in gallery with slide through images

我正在开发 Android 相机应用程序,并希望拥有大多数相机应用程序中的功能:

单击预览图标可打开图库,其中显示当前照片并允许轻扫相机文件夹中的所有图像。

当我使用 Intent.ACTION_VIEW 时,图库只显示 1 张图像,无法浏览目录中的其他照片。

是否有任何额外的意图标志 Intent.ACTION_VIEW 以获得此类行为?

是否有解决此类问题的方法?

Are there any extra flags for intent Intent.ACTION_VIEW to get such behavior?

没有

不要求 Android 设备具有能够 "shows current photo and allows to swipe through all images in the camera folder" 的应用程序。对于那些碰巧有这样一个应用程序的设备,没有标准的 Intent 结构要求应用程序 "shows current photo and allows to swipe through all images in the camera folder".

Is there any workaround to get such behavior?

为此编写您自己的UI。

@CommonsWare 可能听起来有点刺耳,但如果您要制作一个应用程序,不要指望您只需要一些神奇的 Intent 调用就可以为您完成所有工作。

对于您想实现的那种事情,请查看 ViewPager,它可以让您在不同的视图之间滑动(然后每个视图都会显示一张图像)。 Chris Bane 提供了一个很好的自定义视图,允许查看、缩放和滚动图片:https://github.com/chrisbanes/PhotoView

OpenCamera AlmalenceGUI.openExternalGallery() 使用未记录的 action="com.android.camera.action.REVIEW" 在我的 android-4.2.2 中以滑动模式打开图库。

private void openExternalGallery(Uri uri)
{
    try
    {
        Intent intent = new Intent("com.android.camera.action.REVIEW", uri);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        ApplicationScreen.instance.startActivity(intent);
    } catch (ActivityNotFoundException ex)
    {
        try
        {
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            ApplicationScreen.instance.startActivity(intent);
        } catch (ActivityNotFoundException e)
        {
            Log.e("AlmalenceGUI", "review image fail. uri=" + uri, e);
        }
    }
}