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

I'm doing a chat, and In this chat, some messages will be links to a specific url (this url opens a document viewer in the server).
The links look, like this: http://X.X.X.X:8080/DocumentViewer/...
Then I have a webview activity, where I want to open this type of links.
How can "intercept" when the user clicks on this type of links, and open my own webview and not open a "external" browser?

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>

Related

A link generated from the web site does not open in my app but same link genrated from app its work properly

In my android app code Manifest file contains following Intent filter for handling a Link in the app but doesn't work
<intent-filter android:autoVerify="true">
<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="safimoney.com"
android:pathPrefix="/.*/transactions/request-money/confirm/.*" />
</intent-filter>
test it with link generated from web "https://safimoney.com/en/transactions/request-money/confirm/0CnpXE7u5hXRD1JVcZM2APHcYElKZvBZs8GeqimJ" but it doesn't ask for an open link in the app.
If you want your app to open a link, use below code.
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
It will ask to select browser while opening this link.
You wanna do a Deep Link, right?
<intent-filter>
<data
android:host="open"
android:scheme="companyName" />
<data
android:host="companywebsite.com"
android:scheme="http" />
<data android:scheme="https" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
I would suggest for you take a look in Branch.io for link-app solutions.
But if you wanna make a webView inside your app this tutorial can help you.
This is one of the cases where developer.android website has everything that you need, even code examples. Just need to ready with a lot of attention. Hope it helps
EDIT
About your data, looking on android developer website, this should be the better way to set:
<data
android:scheme="https"
android:host="safimoney.com"
android:pathPrefix="/en/transactions/request-money/confirm/" />
But even after this you should add a data like this
<data android:scheme="safimoney"
android:host="/en/transactions/request-money/confirm/" />

Android deep links url pattern

I want to include deep links handle in my Android app. But I can't find how we can register only some patterns of urls? For example, I want my app open only if the url contains "london" keyword in it. How can I implement this? Something like this:
<intent-filter android:autoVerify="true">
<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.mysite.com" android:pathPrefix="/*/london/*" android:scheme="https" />

Deep linking Android from chrome

The app opens when I load from applications. However, it does not load when I try to load from he chrome. This his is my manifest file
<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="spectacles"/>
</intent-filter>
Take a look at this answer:
"Essentially, the Chrome team feels that if a user actually types something into the address bar, no redirect should ever happen. As you've discovered, this is counter to behavior in all other browsers."

Opening the custom file format in my application instead of downloading it on Android

When user type the url to my .someExt file in his web browser (on Android Phone), the message appears:
This content is unsupported content. Do you really want to download?
Instead, I would like to associate the .someExt (my custom file extension) with my Android Application (that the user has downloaded previously) so when user type the url to .someExt in browser my Application will open the file.
How to achieve it? I guess it has to be done with manifest and some "handle" method in my Activity.
Based on: Associate App with file extension - Intent filter Not working?
I have used:
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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:mimeType="application/someExt" />
</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:host="*" />
<data android:scheme="file" />
<data android:scheme="smb" />
<data android:scheme="content" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.someExt" />
</intent-filter>
</activity>
Now, when user type the url to my .someExt the file is being downloaded and I can open it when downloading is done (so my Application will run it). But I don't want all those additional clicks - I want it to be:
User click the link to .someExt on the website.
The .someExt opens in my Android Application.
And not the:
User click the link to .someExt on the website.
The file starts to download.
User open "downloads" and click on downloaded file.
The .someExt opens in my Android Application.
I don't think you can realize this feature in Android with different kind of browsers. The URL user type is handled by the browser most of the time. How to deal with the scheme is decided by the behaviors of the browser. If your scheme is http, the browser will try to open with it own and handle by itself.
Currently, most browsers add support for market scheme. If the URI's scheme is market, it will jump to Google Play or other markets.
But is can be done from other app with Intent.
Declare your activity like following to receive the ACTION_VIEW action.
<activity
android:name=".MainActivity2Activity"
android:label="#string/title_activity_main_activity2">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="com.example.myapp"
android:mimeType="*/*"
android:pathPattern=".*\\.someExt"
android:scheme="http" />
</intent-filter>
</activity>
From other apps, you could do like this.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://com.example.myapp/test.someExt"), "*/*");
intent.setPackage("com.example.myapplication");
startActivity(intent);

How to call an app mobile via web view?

is there a solution to call a mobile app via a link in a web page(my web page is a web view in a mobile app). For example, I want to call facebook app when tap on a link.
You need to create an <intent-filter>. See Launch custom android application from android browser.
For the simplest case, you need to add something like this to your AndroidManifest.xml:
<intent-filter>
<data android:scheme="http" android:host="your-url-.com"/>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
You have to add an Intent filter in Manifest file like this -
<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.tamrakar.in"
android:path="/test"
android:scheme="http" />
</intent-filter>
Hope this helps.

Categories

Resources