You know that a hyperlink can launch a new email or open the browser – but wouldn’t it be nice if they could also invoke our apps. Wouldn’t it be even nicer if I told you that it’s possible in BlackBerry 10? Consider it told.
Most of you might have heard about invocation framework and how it allows apps to register for URI schemes and patterns. That’s exactly what we need to use and here is how to do that in your bar-descriptor.xml.
<invoke-target id="com.example.taco.hrefs"> <invoke-target-name>Taco Quest</invoke-target-name> <icon><image>taco.png</image></icon> <type>card.previewer</type> <filter> <action>bb.action.VIEW</action> <mime-type>*</mime-type> <property var="uris" value="taco://"> </filter> </invoke-target>
Once registered, anyone can invoke with that URI pattern, but that involves another app intentionally invoking your app. Ideally, we want these URIs to automatically become active links wherever there is text that matches the registered pattern and when clicked, they should invoke our app.
Here is the trick – as long as the text in an email or in a web page is wrapped with an <a href> tag it will become a hyperlink that invokes your app. This isn’t just limited to emails and web pages. In fact, any UI component that supports or recognizes <a href> tags will act in the same way across Native, Cascades, Adobe AIR and WebWorks apps.
Note that this will not work for http, https and other schemes that the core applications register for because they are given priority over others by default. However, it is super useful to register for a custom URI such as “myapp://” and have all <a href=“myapp://”>…</a> lead to your app.
Cool eh? Enjoy.