Android Respond To URL in Intent - android

I want my intent to be launched when the user goes to a certain url: for example, the android market does this with http://market.android.com/ urls. so does youtube. I want mine to do that too.

I did it! Using <intent-filter>. Put the following into your 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:host="www.youtube.com" android:scheme="http" />
</intent-filter>
This works perfectly!

You might need to allow different combinations of data in your intent filter to get it to work in different cases (http/ vs https/, www. vs no www., etc).
For example, I had to do the following for an app which would open when the user opened a link to Google Drive forms (www.docs.google.com/forms)
Note that path prefix is optional.
<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="www.docs.google.com" />
<data android:host="docs.google.com" />
<data android:pathPrefix="/forms" />
</intent-filter>

Related

Android intent filter pathPattern doesn't seem to work

Let's say i have two urls and I want to take the user to different activities based on the url pathPattern since both of them have the same pathPrefix.
URL1: /Reviews/xxx-SRCH_xxx.htm
URL2: /Reviews/xxx-Eyyy.htm
xxx: alphabets with no max. limit (ie. it could be as short as 2)
yyy: is numbers with no max. limit.
I want to look for SRCH_ in URL1 and take the user to Activity1 and look for -E[0-9].htm in URL2 to take them to Activity2.
There's not much documentation I could find.
These attributes are meaningful only if the scheme and host attributes are also specified for the filter.
Things I tried.
<activity android:name="com.mycompany.myapp.ui.activities.HomeActivity"
<intent-filter>
<data android:scheme="https" />
<data android:host="www.mycompany.com" />
<data android:pathPrefix="/Reviews/" />
<data android:pathPattern="/.*-E*\\.htm" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<android:name="com.mycompany.myapp.ui.activities.DetailsActivity"
<intent-filter>
<data android:scheme="https" />
<data android:host="www.mycompany.com" />
<data android:pathPrefix="/Reviews/" />
<data android:pathPattern="/.*-SRCH_*.*\\.htm />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
The problem I'm having is that when I click either of those urls, it shows two instances of my app icon (I assume it corresponds to each activity).

How does Google App Indexing handle https://www.example.com vs https://example.com

I just finished setting up App Indexing for my website's Android app and I did a few tests by passing https://www.example.com/test and https://example.com/test according to the instructions specified in https://developers.google.com/app-indexing/android/test (Testing URLs with Android Studio)
This is my intent filter in my Android Manifest:
<intent-filter android:label="#string/filter_title_default">
<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="example.com"
android:pathPrefix="/test" />
</intent-filter>
I noticed that https://www.example.com/test fails, but not https://example.com/test. How do I fix this, other than specifying another intent filter for www.example.com/test?
As far as I know, each host should be added in a new intent filter. You can refer to this doc for more info.
Cheers,
MB
You can specify multiple data elements for your intent filter, for all URLs you need to handle with your activity.
To handle both www and non-www links to your domain you can change your intent filter to this:
<intent-filter android:label="#string/filter_title_default">
<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="example.com"
android:pathPrefix="/test" />
<data android:scheme="https"
android:host="www.example.com"
android:pathPrefix="/test" />
</intent-filter>
Or to handle example.com and any subdomain, you can include a wildcard at the beginning of the host:
<intent-filter android:label="#string/filter_title_default">
<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="example.com"
android:pathPrefix="/test" />
<data android:scheme="https"
android:host="*.example.com"
android:pathPrefix="/test" />
</intent-filter>
Also, if you want to match all your domain URLs, you must remove the pathPrefix attribute completely, as setting it to "/" doesn't work as expected.

How to appear my app in YouTube share via list?

YouTube App for tablets has a sharing-option. For example: I watch a video in the YouTube app and click the button to share. Bluetooth, Googlemail, and Dropbox appear for me. I wonder how i can list my app there? Which intent-filter has my app to have?
Here i have tried. But this is not working for me. I am using Android Kitkat version.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="audio/*" />
<data android:mimeType="video/*" />
<data android:mimeType="text/*" />
<data android:scheme="content" />
<data android:scheme="file" />
</intent-filter>
You have to put this intent filter inside an Activity tag in your Manifest file...
<intent-filter>
<action
android:name="android.intent.action.SEND" />
<category
android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="image/*" /> /* WRITE THE CORRECT TYPE */
</intent-filter>
Then you have to develop the way your Activity handles the data from the current intent.

Allow Application to Open a Custom Zip File From Gmail

My Problem
I have a custom zip file with the extension .trap which I email to myself and receive in my Gmail account on my android phone.
I need to be able to say that my application can open this file and handle it accordingly. I have looked all over and there are many variations out there but none seem to have worked for me. I did also see that Android doesn't allow the opening of .zip files.
Here are my intent filters I add to my android manifest.
<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:scheme="http" />
<data android:host="*" />
<data android:pathPattern=".*\\.trap" />
</intent-filter>
<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:scheme="http" />
<data android:host="*" />
<data android:mimeType="application/trap" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.trap" />
</intent-filter>
NB: For the MIME type I have also tried */* which doesn't work and just / which stops the app from launching.
My Questions
Can android open zip files from an email?
How to specify that my application is able to handle the opening of this file type.
Thanks in advance
The other answers are both good answers and may work for someone. They definitely helped me understand it more so thumbs up to them.
The method that worked for me however is shown below.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.trap" />
<data android:pathPattern=".*..*..*..*..*..*.trap" />
<data android:pathPattern=".*..*..*..*..*.trap" />
<data android:pathPattern=".*..*..*..*.trap" />
<data android:pathPattern=".*..*..*.trap" />
<data android:pathPattern=".*..*.trap" />
<data android:pathPattern=".*.trap" />
</intent-filter>
I hope this helps someone.
Can android open zip files from an email?
Only with the help of an app.
How to specify that my application is able to handle the opening of this file type.
This may work:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/trap" />
</intent-filter>
This assumes that the email client sending this message uses your custom MIME type (which, BTW, probably ought to be in the vnd. namespace).
Your existing filters assume that the attachment is a file or an HTTP request, whereas Gmail attachments present themselves to you via a ContentProvider (content:// scheme).
You can have BROWSABLE in there if you want as well as DEFAULT, if you think that you will also be downloading application/trap files via a Web browser.
Because GMail acts as a content provider, you'll need to add the content scheme, like so:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/*"
host="*"
android:pathPattern=".*.trap"
android:scheme="content" />
</intent-filter>

Android Intent-Filter for http address

I am trying to intercept a couple different links with my app, and I am having trouble with the intent-filter data parameters to do it.
Here are the 2 types of links that I want to intercept
http://www.domain.com/#id=abcdef123346
http://www.domain.com/social/landing/abcdef123456
I have already decided to have a separate activity to intercept both links and use java regex to start the correct activity. However I can't seem to capture just these two formats without capturing something like http://www.domain.com/abc123
<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="www.domain.com"
android:pathPattern="/#id.*" />
</intent-filter>
This is what I am currently trying to intercept type 1 and for some reason it isn't working.
This intent-filter correctly intercepts type 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" />
<data android:host="domain.com" />
<data android:host="www.domain.com" />
<data android:pathPrefix="/share/web" />
<data android:pathPrefix="/social/landing" />
</intent-filter>
Thanks,
I think that the string that pathPattern is matching is "/", and "#id..." is omitted because it is part of the fragment. If you used http://www.domain.com/id/abcdef123456 instead, pathPattern could match "/id/.*" because it is part of the path.

Categories

Resources