Intercepting URL from default browser

Intercepting URL from default browser

This code intercepts an URL opened from the default Internet browser in Android and it is sent to your application. Using this code, you are able to use the URL for your own proposes. The user will be informed that your application can be used to open the link.

Add intent-filter to the Activity that will intercept the link.

<!-- Manifest.xml -->

  <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:pathPrefix="" />

Handle link in the Activity:


public void onCreate(Bundle savedInstanceState) {

  if (Intent.ACTION_VIEW.equals(action)) {
    String link = intent.getData().getScheme() + intent.getData().getSchemeSpecificPart();
    // method to handle the link