This question already has answers here:
Launching custom Android application from Android browser / Chrome
(3 answers)
Closed 6 years ago.
Hey I want my website url to open my android when the user open this url in the browser
What i did is
<intent-filter>
<data android:host="www.example.com" />
<data android:scheme="https" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
and my webiste url is www.example.com
but it doesn't work
any way on how to achieve this
Thanks
Try This:
Add data tag in <intent-filter> with host
<intent-filter>
<data android:host="www.example.com" />
<data android:scheme="https" />
<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"
android:host="www.example.com" />
</intent-filter>
You need to combine your <data> elements into one:
<data android:scheme="http" android:host="www.example.com" />
You can do it via href, example
Take a QR code
Link:
https://developer.chrome.com/multidevice/android/intents
I want to open up a file in my application with a custom extension say .ccf
And read the content of the file. it's a simple text file nothing else but i am changing the extension because i want only my app to read it.
i am using following intent-filter to open that file. but i don't know how to read the contents.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.ccf" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.ccf" />
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.ccf" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.ccf" />
</intent-filter>
Just like .PDF file open in Adobe reader.
Need help.
I have a custom file extension like .foo that I want to associate my app with. I created 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:scheme="file" android:pathPattern=".*\\.foo"/-->
<data android:scheme="file" android:mimeType="*/*" android:pathPattern=".*\\.foo" android:host="*"/>
</intent-filter>
The problem is that this doesn’t work on some devices. For example, only the following works with the Samsung Galaxy S3 (Android version: 4.4.2):
<data android:scheme="file" android:mimeType="*/*" android:pathPattern=".*\\.foo" android:host="*"/>
However, with a LG G2 (Android version: 4.4.2), only this line works:
<data android:scheme="file" android:pathPattern=".*\\.foo"/>
To make it even worse, the Nexus 7 (Android-Version: 5.0) doesn’t seem to recognize custom file endings at all.
Has anyone ever had a similar problem and knows a solution?
Patterns for files are screwy... seems to be on purpose done by the developers.
It seems that the file pattern will work differently on different devices but it only depends on de depth of the file structure. See this link: pathPattern to match file extension does not work if a period exists elsewhere in the file name?
I think this way works for me (change "custom" with the extension you want to use) :
<activity android:name=".MainActivity">
<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:pathPattern=".*\\.custom"/>
<!-- These additional pathPattern blocks are to allow for paths with
additional periods in them. See:
http://stackoverflow.com/questions/3400072/pathpattern-to-match-file-extension-does-not-work-if-a-period-exists-elsewhere-i/8599921 -->
<data android:pathPattern=".*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.custom"/>
<data android:host="*"/>
</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:pathPattern=".*\\.custom"/>
<data android:pathPattern=".*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.custom"/>
<data android:host="*"/>
</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/vnd.ni.custom" android:scheme="file"/>
</intent-filter>
</activity>
I am saving a binary to a file with a custom extension for instance .custom. How do I save it to a specific mime type? I want my app to be called to open that custom file. In the manifest I used / as mimeType but the app gets called even when tapping an image. I used octet-stream but the file doesn't get recognized and the app does not get opened. I just want to save a binary with custom extension and the OS would call my app when it encounters this 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="file" />
<data android:mimeType="application/octet-stream" />
<data android:pathPattern=".*\\.test" />
<data android:host="*" />
</intent-filter>
Finally, after several views only without answers I figured it out. The post on this link helped me resolve my issue.
https://publish.illinois.edu/weiyang-david/2013/04/11/how-to-write-intent-filter-dealing-with-mime-type-problem/
This example was it
<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=".*\.pdf" />
</intent-filter>
I replaced the scheme to "file" and replaced with my pathPattern. Removing the mimeType was key to solving my issue. File browsers now suggests to open the custom file with my app.
I have seen numerous answers on here about creating an intent filter for a custom file extension, but none of them seem to be answering my question:
I have an intent filter that works right now... when I browse for my file or when I open it from an email attachment, my app will appear in the list. The file itself has a custom extension of "tgtp", but it is basically just an xml file.
The problem I am having is that although this intent filter works, it also appears to add my app to every chooser for every type of file on my phone. An example would be if I clear my contacts app defaults and click on one of my contacts, it says my app can open it.
I've tried dozens of different combinations of intent filters with different schemes, mime types, etc... and some still let me open the file if i browse with a file browser, but I specifically need to be able to open email attachments and open as file browser. I am yet to find an intent filter(s) that allow me to do that without making my app available for every other intent chooser.
Here is my current intent-filter that uses my app to open everything:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.tgtp" />
</intent-filter>
Thank you in advance
The only way to solve this problem is add scheme and host attributes to your intent filter:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.tgtp" />
<data android:host="*" />
</intent-filter>
That is because in documentation says that android:pathPattern only works if has an scheme and host defined.
http://developer.android.com/guide/topics/manifest/data-element.html
Hope it helps.
I've been struggling with this quite a bit for a custom file extension, myself. After a lot of searching, I found this web page where the poster discovered that Android's patternMatcher class (which is used for the pathPattern matching in Intent-Filters) has unexpected behavior when your path contains the first character of your match pattern elsewhere in the path (like if you're trying to match "*.xyz", the patternMatcher class stops if there's an "x" earlier in your path). Here's what he found for a workaround, and worked for me, although it is a bit of a hack:
PatternMatcher is used for pathPattern at IntentFilter But,
PatternMatcher's algorithm is quite strange to me. Here is algorithm
of Android PatternMatcher.
If there is 'next character' of '.*' pattern in the middle of string,
PatternMatcher stops loop at that point. (See PatternMatcher.java of
Android framework.)
Ex. string : "this is a my attachment" pattern : ".att.". Android
PatternMatcher enter loop to match '.' pattern until meet the next
character of pattern (at this example, 'a') So, '.' matching loop
stops at index 8 - 'a' between 'is' and 'my'. Therefore result of this
match returns 'false'.
Quite strange, isn't it. To workaround this - actually reduce
possibility - developer should use annoying stupid pathPattern.
Ex. Goal : Matching uri path which includes 'message'.
<intent-filter>
...
<data android:pathPattern=".*message.*" />
<data android:pathPattern=".*m.*message.*" />
<data android:pathPattern=".*m.*m.*message.*" />
<data android:pathPattern=".*m.*m.*m.*message.*" />
<data android:pathPattern=".*m.*m.*m.*m.*message.*" />
...
</intent-filter>
This is especially issued when matching with custom file extention.
I have the exact same problem, and in my case, both other answers don't work. The closest I came is when I combine both benjamin and sabadow's answers, -and- leave out the dot in the extension, so like this: (i'm using my custom ".trk" extension)
<!-- For opening/viewing only trk-files: (works in google drive and "File Manager", not gmail) -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" android:mimeType="*/*" android:pathPattern=".*trk" android:host="*" />
<data android:scheme="file" android:mimeType="*/*" android:pathPattern=".*t.*trk" android:host="*" />
<data android:scheme="file" android:mimeType="*/*" android:pathPattern=".*t.*t.*trk" android:host="*" />
<data android:scheme="file" android:mimeType="*/*" android:pathPattern=".*t.*t.*t.*trk" android:host="*" />
<data android:scheme="file" android:mimeType="*/*" android:pathPattern=".*t.*t.*t.*t.*trk" android:host="*" />
<data android:scheme="file" android:mimeType="*/*" android:pathPattern=".*t.*t.*t.*t.*t.*trk" android:host="*" />
<data android:scheme="file" android:mimeType="*/*" android:pathPattern=".*t.*t.*t.*t.*t.*t.*trk" android:host="*" />
<data android:scheme="file" android:mimeType="*/*" android:pathPattern=".*t.*t.*t.*t.*t.*t.*t.*trk" android:host="*" />
</intent-filter>
<!-- For catching attachments in Gmail: (also triggers non-trk-files that aren't associated with some other app, but not non-trk-files that already have one of more associations, strangely) -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="*/*" android:scheme="content" />
</intent-filter>
<!-- For catching share actions from apps: (also triggered by sharing actions for all other file types) -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/*" />
</intent-filter>
It's a bit long, but you might not need all lines, like the SENDTO and SEND_MULTIPLE actions. I just need it to work in all cases where it could work. Sadly it also triggers in some, but not all, other cases.
One possible answer is shown
here
. Basically, try the following intent filter inside the desired activity tag to open:
<intent-filter android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.OPENABLE" />
<data android:host="*" />
<data android:mimeType="application/octet-stream" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.yourextension" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.yourextension" />
<data android:pathPattern=".*\\..*\\..*\\.yourextension" />
<data android:pathPattern=".*\\..*\\.yourextension" />
<data android:pathPattern=".*\\.yourextension" />
<data android:scheme="content" />
</intent-filter>