2

Suppose I have a web page, and I load that page in a browser on an android device. What I expect is, when I click a button in the web page, an app can be opened.

Is there any way to do that? Thanks a lot.

XWang
  • 679
  • 2
  • 7
  • 19
  • Yes, there is. In your scenario, are you the web developer of that web site? Or do you intend to have an Android app pre-installed on that device? In either case, it can be done. It's just that the exact mechanism you will use will depend on which part you're going to have control over. – Stephan Branczyk May 08 '13 at 06:12

4 Answers4

0

If you have the option to customize the app in question, you could add an Intent Filter for a specific URI scheme which is unique to your app. Then in the click event for the button of the web page, use this URI scheme to launch your app.

For example, Google Play uses a market:// scheme to open the Google Play app from links.

Raghav Sood
  • 79,170
  • 20
  • 177
  • 186
0

using IntentFilters it is possible.. Chack out the following code:-

<intent-filter>
    <data android:scheme="**myapp**" />
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" /> <--Not positive if this one is needed
    ...
</intent-filter>

now you can start your app like myapp://

d3m0li5h3r
  • 1,960
  • 16
  • 31
0

you can achieve this using <intent-filter> with a <data>. For example, to handle all links to sample.com, you'd put this inside your in your AndroidManifest.xml:

    <intent-filter>
    <data android:scheme="http" android:host="sample.com"/>
    <action android:name="android.intent.action.VIEW" />
</intent-filter>

this one was well explained by Felix in his answer here

hopes this helps you...

Community
  • 1
  • 1
Renjith K N
  • 2,467
  • 2
  • 27
  • 50
0

you can use getIntent().getData() which returns a Uri object. You can then use Uri.* methods to extract the data you need. For example, let's say the user clicked on a link to http://twitter.com/status/1234:

Uri data = getIntent().getData();
String scheme = data.getScheme(); // "http"
String host = data.getHost(); // "twitter.com"
List<String> params = data.getPathSegments();
String first = params.get(0); // "status"
String second = params.get(1); // "1234"    

You can do the above anywhere in your Activity, but you're probably going to want to do it in onCreate(). You can also use params.size() to get the number of path segments in the Uri. Look to javadoc or the android developer website for other Uri methods you can use to extract specific parts.

user2307412
  • 21
  • 1
  • 3