android magnet link data filter - android

I want to launch an Android activity from my app when the user selects a magnet link in the browser.
According to the docs, A URI is specified by separate attributes for each of its parts:
scheme://host:port/path or pathPrefix or pathPattern
The problem with magnet links is that they have a different pattern, like magnet:?xt=......
I tried something 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:scheme="magnet"
android:host="*"
/>
</intent-filter>
but it did not work (the activity didn't launch when I opened a magnet link in my browser). Could you help me in correctly declaring an intent filter for magnet links?

I got this to work for me:
<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="magnet"
/>
</intent-filter>
Basically, I removed android:host

Related

It is mandatory to specify the "android:host" for all url in android for Deep Link?

I have to filter two URL for an activity. I'm using Deep Links to App Content by specifying a url for the Deep Link Screen.
These are my urls
appdemo://deeplink
native://
I'm already added these two scheme to my Android Manifest file, looks like
<data android:scheme="appdemo" android:host="deeplink" />
<data android:scheme="native" />
my question is that, by providing scheme and host on the Android Manifest file, native:// this link does not work. it requires the android:host name also
(native://deeplink).
It is mandatory to specify the "android:host" for all url in android?
If no, how can i specify the different scheme.
The idea beside deep links is to use the same structure as normal links:
scheme://host/path
The main benefit is that you can teach your app even to open some Internet links, e.g. to open youtube (Android will ask, if you want to open in browser or YouTube app or your app):
<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"/>
<data android:scheme="https"/>
<data android:host="youtube.com"/>
<data android:host="www.youtube.com"/>
<data android:host="m.youtube.com"/>
<data android:host="youtu.be"/>
<data android:pathPattern=".*"/>
</intent-filter>
So, answering your questions:
Yes, it is mandatory to specify both scheme and host.
A good practice of handling two different links in one activity is to use different paths. 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:scheme="appdemo" android:host="deeplink" android:pathPrefix="/path1/"/>
</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="appdemo" android:host="deeplink" android:pathPrefix="/path2/"/>
</intent-filter>
Then you can get your path in onNewIntent:
Uri data = intent.getData();
String path = data == null ? null : data.getPath();
...and build some logic depending on this path.
The above answer is acceptable and, in my case i want to navigate a new activity through this intent filter, and i got some information to the above answer and made some changes in my code and fix the issue.
Also I'm not specifying the host name for my second intent.
<activity
android:name=".DeepLinkActivity"
android:exported="true"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.Launcher">
<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="appdemo" android:host="deeplink" />
</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="native" />
</intent-filter>
</activity>
Now my both url navigate to DeepLinkActivity.
appdemo://deeplink
native://
Do you think this is not an optimized way?
Any other suggestions for that please mention.

Discarding deep link if it contains specific path

I have an implementation of deeplink in my manifest which is working fine
<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="blablabla.com"
android:scheme="https" />
<data
android:host="${applicationId}"
android:scheme="bla" />
</intent-filter>
I am wondering is there any way to NOT ACCEPT a deep link URL if it contains a specific path? E.g. Do not accept (don't open the app) if blablabla.com/specificPath but do accept any other paths with the same hostname.
Android Deep Links does not provide a way to explicitly exclude URLs, the best practice is define specifically the urls that you want to access to your app using deep Links.
In this case to access URLs like :
www.blablabla.com/specificPath
www.blablabla.com/specificPath/
www.blablabla.com/specificPath/default.aspx
www.blablabla.com/specificPath/other/
You will define the configuration of your intent filter using android:pathPrefix as:
<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="blablabla.com"
android:scheme="https"
android:pathPrefix="/specificPath" />
</intent-filter>

Android deeplink two separate activities

I have two activities to deep link
One activity to link with follow url
http://abc.or/deals
Following is intent filter for it
<intent-filter>
<data
android:host="abc.or"
android:path="/deals"
android:scheme="http" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Another activity with following url
http://abc.or/deals?category=Air+Conditioner-Refrigerator-
<intent-filter>
<data
android:host="abc.or"
android:path="/deals"
android:pathPattern="*deals/?category*"
android:scheme="http" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
But on clicking any of the url deep link is working for both activies which is the issue how I can fix this
Unfortunately, that won't be possible.
as the path is same in both the intent filters.
As an alternative, to have only one suggestion for the user,
Remove the intent filter from second activity
Parse the URI data fromintent.getDataString() in first activity and redirect the user to second activity on basis of this data.

Open my app by URL from browser's address bar like flipkart does

I writed a simple Android application and added a intent filter like this:
<intent-filter>
<data android:scheme="http" android:host="www.somesite.com" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Now, when I click by link from another application (like GMail) i see a dialog: choose application for run: MyApp or Browser.
But when I type this URL in browser's address bar it just open a site.
How can set up my app like a Google Play, Google+, flipkart? (When I type a http://play.google.com/ - i see a dialog Google Play App or Browser)
Its all about Broadcasts and Intents! The idea is that your app declares in the manifest that it can receive certain messages.
From this answer:
Basically, what you'll need to do is define your own scheme. Something
along the lines of:
<intent-filter>
<data android:scheme="anton" />
<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>
Then you should be able to launch your app with links that begin with the anton: URI scheme.
add this source into manifest file
Adding the following fixed the issue:
So the intent filter looks like:
<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="example.com"> </data>
<data android:scheme="https"></data>
<data android:pathPattern=".*"></data>
</intent-filter>

Android Intent-filter mimetype and host/scheme

I've seen in some apps that when you click on a link it asks you if you want to open it in an app. I've seen in many posts that you can do
<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.ex-ample.com" android:scheme="http" />
</intent-filter>
I haven't tried it, but every post seems to say it works. What I tried was:
<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="vnd.android.cursor.item/vnd.example.crag" />
<data android:host="www.ex-ample.com" android:scheme="http" />
</intent-filter>
and it doesn't seem to work, I clicked on a link in a text that went to www.ex-ample.com/test/123 and it just opened in a browser.
I'm really wondering two things:
can you use a mineType and a host/scheme attribute together
can you see anything else wrong with this?
can you use a mineType and a host/scheme attribute together
Yes, at least according to the docs on <data>.
can you see anything else wrong with this?
If http://www.ex-ample.com/test/123 does not return a document of MIME type vnd.android.cursor.item/vnd.example.crag on an HTTP HEAD request, your <intent-filter> will not match.

Categories

Resources