接收ACTION_SEND意图从图库意图、图库、ACTION_SEND

2023-09-04 13:27:13 作者:无法阻挡

我想通过一个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));
 
精彩推荐
图片推荐