我试图通过ACTION_SEND意图从Android图库接收图像。我已经设置了适当的意图过滤器,画廊打开我的应用程序。现在我想知道如何获取图像数据。我无法在互联网上找到任何这样做的例子。我认为路径在intent.getData()中的某处,但是我怎样才能从画廊中拉出该图像?从图库中接收ACTION_SEND意图
8
A
回答
15
在Picasa源代码中找到它。它给出了图像的正确路径。
Intent intent = getIntent();
if (Intent.ACTION_SEND.equals(intent.getAction())) {
Bundle extras = intent.getExtras();
if (extras.containsKey(Intent.EXTRA_STREAM)) {
Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
String scheme = uri.getScheme();
if (scheme.equals("content")) {
String mimeType = intent.getType();
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(uri, null, null, null, null);
cursor.moveToFirst();
String filePath = cursor.getString(cursor.getColumnIndexOrThrow(Images.Media.DATA));
0
不能确定SEND意图,但处理来自PICK意图的MediaStore相片返回时,它会是这样的:
Uri selectedImage = intent.getData();
AssetFileDescriptor fd = getContentResolver()
.openAssetFileDescriptor(selectedImage, "r");
FileInputStream s = fd.createInputStream();
// your image data processing code here
不过要小心 - 你可以用5+万像素的文件中工作,它可能相当大(特别是如果你将它们解压缩为位图来处理),并且你的内存非常有限。
相关问题
- 1. ACTION_SEND数据意图
- 2. Android ACTION_SEND意图不填充To字段
- 3. 多意图接收器?
- 4. 无法接收ACTION_TIME_CHANGED意图
- 5. BroadcastReceiver无法接收意图
- 6. 如何接收TIME_TICK意图
- 7. 如何旋转从相机意图接收的位图图像
- 8. 如何接收意图。 ACTION_PACKAGE_ADDED意图。 ACTION_PACKAGE_REMOVED在appwidget中?
- 9. 在广播接收器中接收呼叫意图
- 10. ACTION_SEND意图是否有额外的指定收件人的名字?
- 11. 从非活动类中的意图(Bundle)接收值
- 12. 从等待中的意图接收广播的Android问题
- 13. 标题意图在Android应用程序中的Action_SEND
- 14. MainActivty中的意图回收
- 15. 根据偏好的意图接收器
- 16. 广播意图接收空值
- 17. 确定有效的意图接收器
- 18. java.lang.RuntimeException:接收广播错误意图
- 19. 无法接收广播包的意图
- 20. 权限拒绝:接收意图{act = com.google.android.c2dm.intent.REGISTRATION
- 21. 错误接收广播意图问题
- 22. 意图和广播接收器故障
- 23. 广播接收器接收不到意图
- 24. 未从数据库中收集图像
- 25. 如何建立活动的意图和从片段接收
- 26. BroadcastReceiver没有从服务内部接收意图
- 27. 从接收器发送的意图与延迟
- 28. 需要帮助启动Android的YouTube的意图接收从Webview
- 29. 是否可以从广播接收机启动意图?
- 30. 如何从c2dm消息接收者调用意图开关
在哪个文件中以及该文件的位置是要放置的。 – 2015-04-08 10:17:43