【问题标题】:Android : Intent for viewing multiple imagesAndroid:查看多张图片的意图
【发布时间】:2011-07-07 12:06:03
【问题描述】:

我的活动可以显示图片库,我想定义一个“意图过滤器”,表明我的应用可以打开多张图片。例如,在用户拍照并想要浏览它之后,选择器对话框应该建议我的应用程序。

我知道清单中的这段代码只适用于一张图片:

<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:mimeType="image/*" />
</intent-filter>

但它不适用于多张图片...

我认为 mimetype 的值不正确...但是打开媒体提供者图像的正确 mimetype 是什么?

以下是查看 google.note 的意图过滤器示例:

<intent-filter android:label="@string/resolve_edit">
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
</intent-filter>

我尝试将“note”替换为“image”,但它不起作用......有什么想法吗?

我终于拿到了Gallery项目的源代码,这里是manifest文件:https://android.googlesource.com/platform/packages/apps/Gallery/+/master/AndroidManifest.xml

<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="vnd.android.cursor.dir/image"/>
</intent-filter>

但它在我的 Nexus S 上无论如何都不起作用......

我在 Android 开发者网站上找到了这个:

对于多条记录:

vnd.android.cursor.dir/vnd.yourcompanyname.contenttype

例如,对所有火车记录的请求,如以下 URI,

content://com.example.transportationprovider/trains

可能会返回此 MIME 类型:

vnd.android.cursor.dir/vnd.example.rail

【问题讨论】:

  • 你的意思是你想要一个布局中的多个图像?
  • 我的意思是我在同一视图上显示图像矩阵,例如网格视图。
  • 那么有什么问题吗?为什么你不使用贪婪视图

标签: android intentfilter


【解决方案1】:

默认的图像查看器没有公开这样的 API。并且格式或数据会因应用程序而异。没有适用于所有应用程序的通用解决方案。

最好的方法,也许是自己编写一个小活动,它公开一个意图,该意图接受一组 Uris 并显示所有这些图像的缩略图。

当您单击缩略图时,您可以启动单个图像 Intent 以查看该特定图像。


给你:

从 Android 源代码中获取。以前应该在那里看过。

https://android.googlesource.com/platform/packages/apps/Gallery3D/+/master/AndroidManifest.xml

【讨论】:

  • 这很奇怪,因为在我的 Nexus S 上,当我从相机切换到图像查看器时,会打开一个对话框选择器并为我推荐几个应用程序:quickpic 或 Gallery 3D...所以看起来可能...
  • 好吧,这些应用程序建议查看您的所有图像。这是很有可能的。但是,查看特定的图像列表是不同的。好的,我稍后再讨论。
  • Camera App 中的 ImageViewer 启动带有单个图像链接的 Intent,这是您捕获的最后一张图像。对我来说,它只显示一张图像,而不是所有图像。
  • 其实我想显示所有图片:)。如果我选择图库,它会显示所有图像。 quickPic 也是如此。
  • 好吧,我错了,默认图库集中在 Intent 中传递的一张图像上,但所有图像都可用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多