开发者

how to react to an intent of the browser?

Yo guys.

You know when u do options/more/share page from the browser? Well I'd like an activity of mine to show up in the men开发者_运维技巧u of all the apps capable of responding to that browser's intent. Thing is I dunno how to write the intent filter in the manifest. Also how do I access data like URL and title of the page which are supposedly add as extra in the intent?

Cheers


I can't test this at the moment to be sure but I think you can register as a SEND intent filter by using the code below and then you should show up as a provider.

<intent-filter android:label="@string/app_name">
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
</intent-filter>

And then get the text from the extras..

Intent callingIntent = getIntent();
String url = callingIntent.getStringExtra(Intent.EXTRA_TEXT);

I would also suggest looking at the documentation for ACTION_SEND to see the supported mimetypes and extra key value pairs.

From ACTION_SEND documentation:

Input: getType() is the MIME type of the data being sent. get*Extra can have either a EXTRA_TEXT or EXTRA_STREAM field, containing the data to be sent. If using EXTRA_TEXT, the MIME type should be "text/plain"; otherwise it should be the MIME type of the data in EXTRA_STREAM. Use / if the MIME type is unknown (this will only allow senders that can handle generic data streams).

Optional standard extras, which may be interpreted by some recipients as appropriate, are: EXTRA_EMAIL, EXTRA_CC, EXTRA_BCC, EXTRA_SUBJECT.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜