Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get image detail from android.intent.action.SEND?

I want something like this.

enter image description here

NOT the UI, just the data. (The metadata of an image)
In Chrome or some other browser when I browse I get a grid or a list of pictures and when I long press on any image it shows "Share image" option. So when I click on "Share image."

I want my application (REQUIREMENTS)

  1. to show up in the chooser dialog. (Working)
  2. Retrieve info about the image (title, URL, thumbnail) (Not working)

I have done the opposite many times (Sharing some link from my application to another Application like Gmail, WhatsApp, etc).
My question is if it is even possible at all? I have seen many application doing that( You can see in the image ) and have no idea how do they do that.

Here is what I have done so far in terms of code.

Requirement 1 (Working)

I have an activity registered with android.intent.action.SEND intent filter in manifest. (Which makes my activity to appear in the list of Chooser dialog)

Here is the manifest

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

Requirement 2 (NOT Working)

Here is the Activity code to retrieve the data.

public class MyActivity extends AppCompatActivity{

    private TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.phot_save_layout);
        textView = (TextView)findViewById(R.id.count);

        takeValueFunc();
    }

    public void takeValueFunc()
    {
        Intent shareIntent = getIntent();
        if(shareIntent.getAction().equals(Intent.ACTION_SEND))
        {
            String text = shareIntent.getStringExtra(Intent.EXTRA_TEXT);
        }
    }

}

I have done some digging with different browsers, and I read different values for the same image.
I have found a similar question on StackOverflow How to get params from android.intent.action.SEND

But it does not answer my question. :(

like image 492
Rohit Singh Avatar asked Nov 07 '22 10:11

Rohit Singh


1 Answers

Now I want my application to... Retrieve info about the image (title, url, thumbnail)

That is not possible in general.

You are welcome to peruse through the documented extras for ACTION_SEND. You are welcome to come up with your own algorithm for deciding how to interpret those extras. However, there is no requirement that you get the information that you are seeking.

For example, EXTRA_STREAM may hold a Uri. That Uri should have a content scheme. That Uri, plus a ContentResolver, should give you the concrete MIME type (as the MIME type on the Intent may be a wildcard). If that is an image, you can use your favorite image-loading library to load the image into your thumbnail-sized visual representation.

But that's it.

Maybe EXTRA_TEXT and/or EXTRA_SUBJECT will hold other information you might use, but there is no requirement that, say, the HTTPS URL of the image be in either of those. After all, there may not be an HTTPS URL of the image, as the image may not be on the Internet. Similarly, the sending app may not have a "title", let alone send it as part of ACTION_SEND somehow.

like image 170
CommonsWare Avatar answered Nov 15 '22 10:11

CommonsWare