I have an intent filter in the Manifest which handles taps on urls, if url match filter data my application starts.
<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="*" port="8765" android:path="/mypath" />
</intent-filter>
Intent filter works when schema is "http" but if I change it to "https" intent filter doesn't do anything and link starts to load in a browser.
Does anybody know what is the problem here?
Just add an extra data line to your 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="http" android:host="*" port="8765" android:path="/mypath" />
<data android:scheme="https" android:host="*" port="8765" android:path="/mypath" />
</intent-filter>
Related
I have, say, domain example.com. It can work with both https and http. And I have Android client for this service. I want client to be able to open several link types. Here they are:
http://example.com
https://example.com
http://example.com/app
https://example.com/app
These four should be opened on the ListActivity. But also there are another links like:
https://testask.com/i/__some_guid__
https://testask.com/item/__some_guid__
and relevant link without https
They should be opened on another activity, say, DetailsActivity. Currently I have following intent filter for DetailsActivity:
<intent-filter
android:autoVerify="true"
tools:targetApi="m">
<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="#string/root_host_endpoint"
android:pathPattern="/i/.*" />
<data
android:host="#string/root_host_endpoint"
android:pathPattern="/item/.*" />
</intent-filter>
And looks like it works correctly. But I don't understand, how to add MainActivity intent filter to point on root host url and not to overlap DetailsActivity intent filter.
You could have multiple activities with different intent filters. You can differentiate your intent filters using Action/Category/Data. In your case, you have to tweak your Data configuration to have it handle different intents. So MainActivity/ListActivity will have a different Data configuration as opposed to DetailsActivity
<activity android:name=".ListActivity">
<intent-filter
android:autoVerify="true"
tools:targetApi="m">
<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="example.com"
android:pathPattern="/*/.*" />
</intent-filter>
</activity>
<activity android:name=".DetailsActivity">
<intent-filter
android:autoVerify="true"
tools:targetApi="m">
<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="#string/root_host_endpoint"
android:pathPattern="/i/.*" />
<data
android:host="#string/root_host_endpoint"
android:pathPattern="/item/.*" />
</intent-filter>
</activity>
Welp, after some experiments I found that following intent filter is working as expected:
<intent-filter
android:autoVerify="true"
tools:targetApi="m">
<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="#string/root_host_endpoint" />
<data
android:host="#string/root_host_endpoint"
android:path="/" />
<data
android:host="#string/root_host_endpoint"
android:path="/app" />
</intent-filter>
I have a custom file type with the extension .myext.
I've read android doc and many SO posts to understand how to configure intent filter to associate these files to my app. It works but not properly.
When I use this 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/*" />
<data android:pathPattern=".*\\.myext" />
<data android:host="*" />
</intent-filter>
then it links .myext files to my app, but also every file that has no app assoiated. So I can open .otherext file which I don't want.
Then I found this answer https://stackoverflow.com/a/5097734/575481 which suggest to have multiple intent-filter, So I get :
<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=".*\\.myext" />
</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/*" />
</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=".*\\.myext" />
</intent-filter>
but this doesn't seem to work for me.
What I want is that : my apps opens only .myext files. Do you have any idea ?
Furthermore I will need to open some other file ext (.myext1, .myext2) , but I guess once I get the proper intent-filter, I just have to duplicate it for the others with the extension, right ?
I got it. In my case I am trying to get a .ppp from e-mail and it was fetching any file.
this is the working 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="content" android:pathPattern=".*\\.ppp" android:mimeType="application/ppp"/>
</intent-filter>
on your activity's onCreate put a breakpoint and check the values in
getIntent()
specifically mData should give you what to write for the android:scheme and mType what to write for the android.mimeType
As per my study to support a filetype applying filter to an Activity should be enough,
<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="*" android:pathPattern=".*\\.filetype"/>
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.filetype"/>
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.filetype"/>
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.filetype"/>
</intent-filter>
But it does not work for email attachments. When try to open the attachments it only show a message, that no support app found for this filetype.
This snipped code works for email attachments,
<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:pathPattern=".*\\.fileType" />
<data android:host="*" />
<data android:mimeType="application/*" />
</intent-filter>
But for this filter, my application appears for any kind of filetype.
So my question is,
1.What is the proper way to open an email attachment with my app? So that myapp try to open only for the specific filetype.
You need a launcher default to launch based on type.
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.gosylvester.bestrides.ImageTextListViewActivity" />
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/vnd.google-earth.kml+xml" />
</intent-filter>
</activity>
I have an application that wants to handle SGF files. It has these filters in the manifest:
<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="*"/>
<data android:pathPattern=".*\\.sgf"/>
</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="http"/>
<data android:mimeType="application/x-go-sgf"/>
</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="file"/>
<data android:mimeType="*/*" />
<data android:host="*" />
<data android:pathPattern=".*\\.sgf"/>
</intent-filter>
The idea is to handle SGF files opened in the browser or from a file. This was working until recently. I'm not sure exactly when it stopped working, but it wasn't because of a code change. I have another application that is trying to start the activity and it's getting an exception:
No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/gogrinder/Mastering%20the%20Basics/Vol.%202%20-%20One%20Thousand%20and%20One%20Life-and-Death%20Problems/6%20-%20Five-move%20problems%20-%20Black%20to%20kill/prob144.sgf }
Shouldn't this intent match one of the filters above?
Opening an SGF file from the browser or file explorer does cause my activity to start, but doing it programmatically as above doesn't work anymore.
I also have an app which opens SGF files, and it works fine. Compared to your code, I added additional mimeType and host attributes :
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:host="*" />
<data android:scheme="file" />
<data android:pathPattern=".*\\.sgf" />
<data android:mimeType="*/*" />
</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="http" />
<data android:pathPattern=".*\\.sgf" />
<data android:mimeType="*/*" />
</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="http" />
<data android:mimeType="application/x-go-sgf" />
</intent-filter>
If it still doesn't work, it may be a problem with the file path. The pathPattern doesn't work very well when the path includes several dots. Check this question :
pathPattern to match file extension does not work if a period exists elsewhere in the file name?
I'm creating an rss aggregator for my Android phone. I'd like to be able to subscribe to an rss feed from the browser since most websites have a subscribe via rss button.
How can I build an intent filter to receive those links?
This question was similar and showed how to create an intent filter to handle browser links:
Make a link in the Android browser start up my app?
However, I don't know how to make it specific to rss feeds.
As an attempt I tried this filter:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="application/rss+xml" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Am I on the right track? What should I be filtering on?
These 3 filters seem to be the ones used by GoogleListen and GoogleReader apps:
<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="*"/>
<data android:pathPattern=".*\\.xml"/>
<data android:pathPattern=".*\\.rss"/>
</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="http"/>
<data android:host="feeds.feedburner.com"/>
<data android:host="feedproxy.google.com"/>
<data android:host="feeds2.feedburner.com"/>
<data android:host="feedsproxy.google.com"/>
</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="http"/>
<data android:mimeType="text/xml"/>
<data android:mimeType="application/rss+xml"/>
<data android:mimeType="application/atom+xml"/>
<data android:mimeType="application/xml"/>
</intent-filter>
Turns out there's a lot of different ways podcasts can be set up so each intent filter will only work for some of them. A lot of different filters need to be used to get the desired effect over most subscribe links.
Here's some of the filters I found that worked:
<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="itpc" />
<data android:scheme="pcast" />
<data android:scheme="feed" />
<data android:scheme="rss" />
</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="http" android:host="*"
android:pathPattern=".*xml" />
<data android:scheme="http" android:host="*"
android:pathPattern=".*rss" />
<data android:scheme="http" android:host="*"
android:pathPattern=".*feed.*" />
<data android:scheme="http" android:host="*"
android:pathPattern=".*podcast.*" />
<data android:scheme="http" android:host="*"
android:pathPattern=".*Podcast.*" />
<data android:scheme="http" android:host="*"
android:pathPattern=".*rss.*" />
<data android:scheme="http" android:host="*"
android:pathPattern=".*RSS.*" />
</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="text/xml" android:scheme="http" />
<data android:mimeType="application/rss+xml" android:scheme="http" />
<data android:mimeType="application/atom+xml" android:scheme="http" />
</intent-filter>
Am I on the right track?
Yes. However:
You don't need the scheme
You are missing the android: prefix in front of scheme, anyway
type should be android:mimeType
Here is a sample application that demonstrates, among other things, responding to links on PDF files.
Could it be that the server doesn't send the right mimetype?
Experiment by adding:
<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=".*\\.rss" />
<data android:pathPattern=".*\\.xml" />
</intent-filter>
Edit:
It's a bit tricky to compose the right set of intent-filters, there's a lot of early returns in the matching algorithm:
https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/content/IntentFilter.java
In your case, the mimetype must match exactly which is 'application/rss+xml' do your sources return that mimetype in the message header?
URL url = new URL("http://www.engadget.com/rss.xml");
URLConnection conn = url.openConnection();
System.out.println("Content-Type:"+conn.getHeaderField("Content-Type"));
Try to:
Make broader filters
Add multiple filters.