Intercepting links from the browser to open my Android app

I’d like to be able to prompt my app to open a link when the user clicks on a URL of a given pattern instead of allowing the browser to open it. This could be when the user is on a web page in the browser, or in an email client, or within a WebView in a freshly-minted app.

For example, click on a YouTube link from anywhere in the phone and you’ll be given the chance to open the YouTube app.

How do I achieve this for my own app?



Android:open app from browser

I need to open the my application from browser when some pattern matching url come,I have implement using Intercepting links from the browser to open my Android app .It is used for url only can it pos

Open Android app from browser

I am trying to open an Android app from a browser. I have read several StackOverflow threads describing a solution to the problem and this is what I have so far: AndroidManifest.xml <activity andro

Open android app from android default browser

I try to open my app from the browser not able to do this till now. I found many solution on web and try to make my code working. a added this code to my manifest file and try to open my app from brow

How to open a specific browser from an android app

I want to open a url in a browser from an Android app. Thats pretty straightforward: How can I open a URL in Android’s web browser from my application? But how can I open the url in a specific browser

Android webview links open in default browser

I have a scenario where links in my webview should open the default android browser. I searched regarding this and I got to know that if we are setting the custom webviewclient in our webview and load

Open file link from android browser in my app

I want to be able to run the standard android browser in the usual way, navigate to a page with a link to a file on it, eg <a href=./myfile.gcsb>click here</a> click the link and have it

Open the native browser from an android app

I have an android phone with multiple browsers installed and I might or might not set a browser to default. So, my question is.. From my App, How do I force open a link only in the NATIVE android bro

Open WebView not browser from preferenceScreen Android

From my PreferenceScreen I want to open links in WebView not browser. Any ideas? Here is part of my xml: <PreferenceCategory android:[email protected]/about> <PreferenceScreen android:[email protected]

Get jQuery w/ Android Cordova Links to open in browser

I have an Android cordova app, and I use jQuery Mobile for the interface. Basically I am trying to get certian links to open in a browser window instead of cordovas childbrowser. I have some code her

Android: Open Play Store links from PhoneGap app

I want to open a link to the google play store from my phonegap 3.4 app. Calling market://details?id=com.google.android.apps.maps leads to an ActivityNotFoundException which is defined here: https://g

Answers

Use an android.intent.action.VIEW of category android.intent.category.BROWSABLE.

From Romain Guy’s Photostream app’s AndroidManifest.xml,

    <activity
        android:name=".PhotostreamActivity"
        android:label="@string/application_name">

        <!-- ... -->            

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http"
                  android:host="flickr.com"
                  android:pathPrefix="/photos/" />
            <data android:scheme="http"
                  android:host="www.flickr.com"
                  android:pathPrefix="/photos/" />
        </intent-filter>
    </activity>

Once inside you’re in the activity, you need to look for the action, and then do something with the URL you’ve been handed. The Intent.getData() method gives you a Uri.

    final Intent intent = getIntent();
    final String action = intent.getAction();

    if (Intent.ACTION_VIEW.equals(action)) {
        final List<String> segments = intent.getData().getPathSegments();
        if (segments.size() > 1) {
            mUsername = segments.get(1);
        }
    }

It should be noted, however, that this app is getting a little bit out of date (1.2), so you may find there are better ways of achieving this.

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        setUrlparams(url);

        if (url.indexOf("pattern") != -1) {
            // do something
            return false;
        } else {
            view.loadUrl(url);
        }

        return true;
    }

}

There are some libraries parse parameters from url automatically.

such as

https://github.com/airbnb/DeepLinkDispatch

&&

https://github.com/mzule/ActivityRouter

The later one is wrote by me. Which can parse parameters to given type, not always String.

Example

@Router(value = "main/:id" intExtra = "id")
...
int id = getIntent().getInt("id", 0);