接收ACTION_SEND意图从图库 [英] Receiving an ACTION_SEND intent from the Gallery

查看:128
本文介绍了接收ACTION_SEND意图从图库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过一个ACTION_SEND意图收到从Android画廊的图像。我已经设置了适当的意图过滤器和库打开我的应用程序。现在我想知道如何得到的图像数据。我无法找到如何做到这一点在互联网上的任何实例。我图所​​示的路径是intent.getData某处(),但究竟如何我拉的形象从画廊?

I am trying to receive an image from the Android Gallery via an ACTION_SEND intent. I have set the proper intent filters and the Gallery opens my app. Now I want to know how to get at the image data. I can't find any examples on the internet of how this is done. I figure the path is somewhere in intent.getData() but how exactly do I pull that image from the gallery?

推荐答案

在Picasa中源发现这一点。它给出图像的正确的路径。

Found this in the Picasa source. It gives the proper path of the image.

    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));

这篇关于接收ACTION_SEND意图从图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆