Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Share browser url to app

Tags:

android

I am writing an app for a community, which has the ability to share URLs.

In the android browser, there is the possibility to forward URLs, for example from my HTC Desire to a BlueTooth Target, to Facebook, to Friend Stream, to Google Mail, to Google+, Mail, SMS and Peep. What I want to achive is to add my app into that list, providing functionality to forward the current URL from the Browser to the App, regardless on which webpage I am currently.

How do I achive that?

like image 594
pmedia Avatar asked Nov 14 '11 18:11

pmedia


1 Answers

You do this with intent-filter, with the action SEND. This filter will take plain texts, images and videos.

<activity android:name="MyActivity">
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain" />
        <data android:mimeType="image/*" />
        <data android:mimeType="video/*" />
    </intent-filter>
</activity>

In your activity you can check getIntent().getAction().equals(Intent.ACTION_SEND) to know you have been started as a send action and getIntent().getType() what type of data you got.

The data itself (Text, image or anything else) can be found via getIntent().getExtras().get(Intent.EXTRA_STREAM) or getIntent().getStringExtra(Intent.EXTRA_TEXT) (Depends on data type and the sending application).

like image 183
H9kDroid Avatar answered Sep 24 '22 00:09

H9kDroid