Intercepting Links from the Browser to Open My Android App

Intercepting links from the browser to open my Android app

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.

Web browser application - how to intercept URL intents?

Try adding both intent filters

        <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="*"/>
</intent-filter>
<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="https"
android:host="*" />
</intent-filter>

How to intercept click on specific url and open own webclient -- Android

I think that you can accomplish this by creating an intent-filter in your AndroidManifest.xml file for the URL pattern that you are interested in. The documentation for the intent-filter's <data> element shows how you can specify a host and a scheme ("html" in your case) to handle URLs.

This answer shows an example where the developer wanted to handle youtube.com URLs. I have included the manifest snippet below for completeness:

<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:host="www.youtube.com" android:scheme="http" />
</intent-filter>

Based on this, I think (I have not done this myself) that your intent filter should look something like:

<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:host="http://X.X.X.X:8080/DocumentViewer/" android:scheme="http" />
</intent-filter>

Android : prevent an app from opening its own links

The following method works for all implicit intents - not limited to your question about browsers.

When you issue an implicit intent (like ACTION_VIEW), the host Android device will check to see whether there is a default app to handle the intent. If there is a default app, then, by default, android will automatically redirect to the app.

However, you can force an app chooser for implicit intents. For this, you need to use Intent.createChooser() method. See this example:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url)); // only used based on your example.

String title = "Select a browser";
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(intent, title);

// Verify the original intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}

how to open my app by clicking on links of my website

In your AndroidManifest.xml file, try adding an intent filter in your <activity> which you want to open from the link

<activity
android:name=".YourActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>

<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>

<data
android:host="www.zoomit.ir"
android:scheme="http"></data>

</intent-filter>
</activity>

assuming www.zoomit.ir is the link which should open the app

Inorder to open this url in webview first get this url by using intent in your activity's onCreate

    String url;
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();

if (data!=null) {
webView.loadUrl(data.getScheme()+"://"+data.getHost()+data.getPath());
}

Now you will have url="www.zoomit.ir/example-post". Use this url to load webview

How to open android application when an URL is clicked in the browser

You have to define a custom Intent Filter in the activity that should be launched when the url is clicked.

Let say that you want to launch the FirstActivity when a user click a http://www.example.com/ link on a web page.

Add this to your activity in the Manifest :

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

When the user will click a HTML link to http://www.example.com/, the system will prompt either to use the browser or your app.



Related Topics



Leave a reply



Submit