Here is my intent-filter code...
<activity android:name="IntentReceiver">
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT" />
<data
android:scheme="http"
android:host="mytix.com"
android:pathPattern="/" />
<data
android:scheme="http"
android:host="www.mytix.com"
android:pathPattern="/" />
</intent-filter>
</activity>
What I want to do is intercept any NFC tags which have a url data type and the url is pointing to http://mytix.com (or http://www.mytix.com).
However the above code doesn't seem to work. Instead my NFC tags just open the browser and go the url in question (which is the right url! :) I've checked).
How do I intercept the intent? What I want to end up with is a tag that will take users to the mobile website if they don't have the app, but if they have the app installed it will take them straight to the app. I believe I am on the right lines, but the code above doesn't work for some reason.
I'm installing the app by building straight to the phone from Eclipse btw - does this make a difference?
Thanks
Tom
What I want to do is intercept any NFC tags which have a url data type and the url is pointing to http://mytix.com (or http://www.mytix.com).
Try NDEF_DISCOVERED, not TAG_DISCOVERED. Android will only support direct launches like this for NDEF-formatted NFC tags. If your NFC tag is using something else, you can't use the <intent-filter> AFAIK, but rather would have to parse the data out yourself.
Here is a book sample project that demonstrates writing a URL to an NDEF-formatted tag (triggered via the Share Page option in a browser app) and responding to NDEF-formatted tags with a specific URL written to them.
Related
I want to launch a specific android app through a NFC card. I don't want android to ask me which app should be opened. It should instantly open my app. How could I do that?
I already tried it with MIME-Types but it did not work. Could i specify my own MIME-Type? Would it be possible to check the MIME-Type text/plain for a specific text(intent filter?)?
For example: I want my app to start when the NFC card has a specific text stored like "test" or something.
The idea is that it should work on every common mobile OS. Therefore an android application link would not work.
You can create your own application mimeType.
You could create a custom mimeType in your NDEF message and then create an intent-filter which matches it exactly. This would mean your app would be launched as it is the most specific filter.
Example:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/vnd.com.my.app.package.customString" />
</intent-filter>
Taken from a previous example I've provided here: https://stackoverflow.com/a/27397938/3312868
I have defined a custom url for my Android application:
<intent-filter>
<data android:scheme="myfoo" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
When I create a web page that has
My Foo
and click on the link from the local browser, my application is launched just fine. However, if I type "myfoo://" directly in the browser, it simply takes me to Google's search listing.
Wondering if there is a setting on the default browser that I need to disable to make my custom url work. Regards.
Wondering if there is a setting on the default browser that I need to disable to make my custom url work.
Probably not. For starters, there is no single "default browser" in Android. Beyond that, browser developers are welcome to do whatever they want with URLs, including having varying behavior based upon where the URL comes from (address bar vs. link vs. JavaScript vs. ...).
Suppose we have an activity to resolve external URL links with a specifix pathPrefix. It's not a problem. The problem is to have a method to make those links is only resolvable with my app.
For example:
We have 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:host="example.com"
android:pathPrefix="/specific_prefix/"
android:scheme="http" />
</intent-filter>
And I want only my app to be used for example for "example.com/specific_prefix/etc". If that eve possible?
And I want only my app to be used for example for "example.com/specific_prefix/etc". If that eve possible?
No.
First, how URLs are interpreted is up to the app interpreting the URLs. Some Web browsers, when they encounter an http URL, will always handle it themselves, rather than seeing if a third-party app has advertised support for it.
Second, in cases where there are two or more apps that claim to support a certain operation, the user chooses which one to use. In your case, Web browsers and your app will claim to handle that URL, and the user can choose whichever of those that the user wants.
With Android 6.0's app links, you can avoid the chooser by default, so if a chooser would have appeared, the user will be taken straight to your app. The user can disable this in Settings, though.
I'm trying to build a simple Android app that sends a Youtube URL to a particular media server. On the Android side, it needs to be activated by the user pressing the share button on a video inside the Youtube app (or browser). However, I'm having extreme difficulty working out how intent filters work in this case.
The following code, for example, makes my app show up in the apps list when I share from youtube (or almost anything else for that matter).
<activity
android:name=".DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName=".MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MyActivity" />
</activity>
However, when I replace the element with anything containing a scheme, for example:
<data android:mimeType="text/plain" android:scheme="https" />
The app no longer appears in the sharing list. I've tried every combination, and nothing seems to work. Any suggestions (general about intent filters, or more specific to Youtube)?
EDIT:
After investigation using Intent Interceptor, I've discovered that links (e.g. from Youtube or the browser) are sent with the DATA field sent to NULL. Other types of intent (for example, a file) appear to have this set to the URL of the file. Presuming that the filter scheme/host/path act on the DATA section of the intent, there is no data there to filter, so links can't be filtered in this regard. Can anyone confirm or clarify this?
I am developing an application on Android and my application needs to be launched whenever a URI like (myscheme://mydata) is clicked on an SMS or Email.
I am using following filter for my 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="secture"/>
</intent-filter>
However on emails and SMS messages, my URIs with the form of myscheme://mydata show up as
regular tests and i cannot click on them to launch my application.
Thanks for help
Edit :
I found out that Linkfy class does something similar however it modifies your own text into links. What I need is modifying other applications such as Email and SMS. So is it possible to change another applications Linkfy?
So is it possible to change another applications Linkfy?
No, sorry.
Instead of myscheme://mydata, use http://mydomain/mypath. You can create an <intent-filter> for this so that you get control instead of the browser, and the resulting URLs will be friendlier to other apps. As a bonus, you can put a real Web page at that URL, so if somebody who does not have your app winds up with your URL (e.g., forwarded email), the URL will still work..