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.
Related
I am trying to configure a deep link intent-filter to open an Android app from a QR Code scanned by the Camera.
The data value of the QR Code is "tagname:datavalue", presumably a "text/plain" mime type, but I don't know this for sure.
In my AndroidManifest.xml I have the following intent within an activity:
<activity
android:name="a.b.activity.DeepLinkActivity"
android:exported="true"
android:theme="#style/FullscreenTheme">
<intent-filter>
<data android:mimeType="text/plain" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
It wants me include a scheme of which there is none; it's just plain text data.
When the QR Code is scanned by the Camera, I can launch Chrome, but I want to add the option of opening my app. Is this possible?
When I add a mimetype without a scheme, Android Studio wants to add a scheme value android:scheme="<some-scheme>" tools:ignore="AppLinkUrlError" to the intent-filter.
<intent-filter android:scheme="<some-scheme>"
tools:ignore="AppLinkUrlError">
<data android:mimeType="text/plain" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
But there is no scheme.
Bonus question: Can I filter on specific values of tagname, for example launch the app if tagname is "apple", but not "orange"?
Add the scheme as the content and it won't show the error again.
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" android:scheme="content"/>
</intent-filter>
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.
Below is my code, where
<activity
android:name=".activities.Profile"
android:screenOrientation="portrait">
<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="somename"
android:pathPrefix="/league/user"
android:scheme="https" />
</intent-filter>
</activity>
I want to avoid opening the activity when url contains proceed as param. Can anyone point me how to do this.
EDIT
Giving an example
somename/league/user?id=100
somename/league/user?id=100&proceed=4
So, i want to avoid the url pointed out in "2" when proceed as param, from opening the activity.
I have URIs like this: http://myapp/category/details and 3 activities that should handle different levels of this structure.
Activity 1 should handle http://myapp
Activity 2 should handle http://myapp/category
Activity 3 should handle http://myapp/category/details
I have problems with finding the combination of right path/pathPattern/pathPrefix for the data tag. In the example below all 3 activities are happy to handle uri like this http://myapp/category/details and the "Complete action using" dialog is displayed with 3 icons of myapp.
Activity 1:
<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="myapp"
</intent-filter>
Activity 2:
<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="myapp"
android:pathPattern="/.*"
</intent-filter>
Activity 3:
<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="myapp"
android:pathPattern="/.*/.*"
</intent-filter>
How to prevent activity 1 from handling the links intended for activity 2 & 3?
(And activity 2 handling links for activity 3)
You can use mime in order to distinguish between the intent
<data android...
android:mimeType: "your specific mime for the intent...can be custom one like activity/activity1
>
then to run your specific Intent using mime do something like
intent.setType("mimeType/mimeSubType");
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(sendIntent);
}
You can also (and should) use pathPrefix in order to distinguish between the paths.
Have a look at data element for more info
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