<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>BlackBerry Developer Blog &#187; sample</title>
	<atom:link href="http://devblog.blackberry.com/tag/sample/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.blackberry.com</link>
	<description></description>
	<lastBuildDate>Wed, 19 Jun 2013 18:00:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='devblog.blackberry.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/9ef0a66c09615fa946c4179662398878?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>BlackBerry Developer Blog &#187; sample</title>
		<link>http://devblog.blackberry.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://devblog.blackberry.com/osd.xml" title="BlackBerry Developer Blog" />
	<atom:link rel='hub' href='http://devblog.blackberry.com/?pushpress=hub'/>
		<item>
		<title>She Said: Leveraging the Power of Foursquare in BlackBerry 10</title>
		<link>http://devblog.blackberry.com/2013/05/she-said-leveraging-the-power-of-foursquare-in-blackberry-10/</link>
		<comments>http://devblog.blackberry.com/2013/05/she-said-leveraging-the-power-of-foursquare-in-blackberry-10/#comments</comments>
		<pubDate>Tue, 07 May 2013 17:40:23 +0000</pubDate>
		<dc:creator>Erin Rahnenfuehrer</dc:creator>
				<category><![CDATA[BlackBerry Jam]]></category>
		<category><![CDATA[BlackBerry Live]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Native SDK Development]]></category>
		<category><![CDATA[Cascades]]></category>
		<category><![CDATA[foursquare]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[social]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=14924</guid>
		<description><![CDATA[We&#8217;ve spoken before about how to integrate your Cascades and WebWorks apps with Facebook, Twitter, and LinkedIn on BlackBerry 10. We&#8217;ve shared samples with you that show how easy it is to invoke these social networking apps in various ways. But there was a big square-shaped hole in our existing sample code. We were missing out on [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=14924&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>We&#8217;ve spoken before about how to integrate your <a href="http://devblog.blackberry.com/2013/03/cascades-socialinvocation/" target="_blank">Cascades</a> and <a href="http://devblog.blackberry.com/2013/02/twitter-and-facebook-cards/" target="_blank">WebWorks</a> apps with Facebook, Twitter, and LinkedIn on BlackBerry 10. We&#8217;ve shared samples with you that show how easy it is to invoke these social networking apps in various ways. But there was a big square-shaped hole in our existing sample code. We were missing out on <a href="https://developer.foursquare.com" target="_blank">Foursquare’s powerful API’s</a> and location database.</p>
<p>So we&#8217;ve updated the <a href="https://github.com/blackberry/Cascades-Samples/tree/master/socialinvocation" target="_new">socialinvocation</a> sample to include examples of how to invoke Foursquare with all of the currently supported invocation parameters.</p>
<p><a href="http://rimdevblog.files.wordpress.com/2013/05/fs1.png"><img class="size-full wp-image-14926 aligncenter" alt="TITLE_IMAGE" src="http://rimdevblog.files.wordpress.com/2013/05/fs1-e1367863197254.png?w=275&#038;h=458" width="275" height="458" /></a></p>
<p>As you can see, Foursquare allows BlackBerry 10 developers to leverage their app in a number of different ways, both through Cards and the Invocation Framework.</p>
<p>Big thanks to <a href="http://twitter.com/kfow35">Kyle</a> from Foursquare who has also documented these features in his sample app:  <a href="https://github.com/foursquare/foursquare-bb10-sdk"><br />
https://github.com/foursquare/foursquare-bb10-sdk<br />
</a></p>
<p>If you want to learn more about Social Invocation and why you should be including it in your app, come to one of our sessions next week at BlackBerry Live!  We’ll be talking about the benefits of integrating with Foursquare and the rest of the Social apps in two sessions:</p>
<p><a href="https://bblive.blackberryconferences.net/2013/connect/sessionDetail.ww?SESSION_ID=1584" target="_blank">JAM37 </a>- Building context-aware applications by leveraging the power of Foursquare APIs, Thursday, May 16</p>
<p><a href="https://bblive.blackberryconferences.net/2013/connect/sessionDetail.ww?SESSION_ID=2718" target="_blank">JAM52 </a>- Get Social: Connecting your app to Facebook, Twitter, Foursquare, and more! Wednesday, May 15</p>
<p>Kyle from Foursquare will be there, and we will show a real world example of how <a href="https://untappd.com/home" target="_blank">Untappd</a> found success by integrating with Foursquare.  Sample apps, best practices, and code snippets will also be presented that will show developers how to quickly get started in both the <a href="https://developer.blackberry.com/html5/" target="_blank">BlackBerry WebWorks SDK</a> and the <a href="https://developer.blackberry.com/native" target="_blank">BlackBerry Native SDK</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/14924/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/14924/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=14924&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2013/05/she-said-leveraging-the-power-of-foursquare-in-blackberry-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0432900fe27aa1429d5e6809cd149a3c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">erahnen</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2013/05/fs1-e1367863197254.png" medium="image">
			<media:title type="html">TITLE_IMAGE</media:title>
		</media:content>
	</item>
		<item>
		<title>Being Social with Cascades</title>
		<link>http://devblog.blackberry.com/2013/03/cascades-socialinvocation/</link>
		<comments>http://devblog.blackberry.com/2013/03/cascades-socialinvocation/#comments</comments>
		<pubDate>Tue, 05 Mar 2013 21:44:35 +0000</pubDate>
		<dc:creator>Erin Rahnenfuehrer</dc:creator>
				<category><![CDATA[Cascades]]></category>
		<category><![CDATA[Native SDK Development]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[Invocation]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[Sharing]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=14079</guid>
		<description><![CDATA[We’ve already learned that YOU ARE AWESOME and your family and friends need to be kept constantly up-to-date on all your amazing adventures. With our new socialinvocation sample we show you how you can share your content using Cascades in your BlackBerry 10 apps. The socialinvocation sample shows you how to invoke Facebook, Twitter, and [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=14079&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>We’ve already learned that <a href="http://devblog.blackberry.com/2013/02/twitter-and-facebook-cards/" target="_new">YOU ARE AWESOME</a> and your family and friends need to be kept constantly up-to-date on all your amazing adventures. With our new socialinvocation sample we show you how you can share your content using Cascades in your BlackBerry 10 apps.</p>
<p>The <a href="https://github.com/blackberry/Cascades-Samples/tree/master/socialinvocation" target="_new">socialinvocation</a> sample shows you how to invoke Facebook, Twitter, and LinkedIn with all the currently supported invocation parameters. You can set your Facebook status, compose a Tweet, upload a picture, invoke a Facebook page or Twitter profile, and much more!</p>
<p style="text-align:center;"><img alt="social-invoke" src="http://rimdevblog.files.wordpress.com/2013/03/social-invoke.jpg?w=288" width="288" /> <img alt="social-invoke-2" src="http://rimdevblog.files.wordpress.com/2013/03/social-invoke-2.jpg?w=480" width="480" /></p>
<p>Besides being an avenue for seeing cute pictures of your high school friends’ kids, social media plays an important role in marketing your apps. Use the invocation framework features to direct users to your company’s Facebook page, display your Twitter feed, or allow users to post screenshots of your app! Effectively employing social media is a great way to attract new users, so be sure to take advantage of the invocation framework’s support of Facebook, Twitter, and LinkedIn.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/14079/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/14079/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=14079&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2013/03/cascades-socialinvocation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0432900fe27aa1429d5e6809cd149a3c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">erahnen</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2013/03/social-invoke.jpg" medium="image">
			<media:title type="html">social-invoke</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2013/03/social-invoke-2.jpg" medium="image">
			<media:title type="html">social-invoke-2</media:title>
		</media:content>
	</item>
		<item>
		<title>How to make Collapsible Items using Cascades and QML</title>
		<link>http://devblog.blackberry.com/2013/01/how-to-make-collapsible-items-using-cascades-and-qml/</link>
		<comments>http://devblog.blackberry.com/2013/01/how-to-make-collapsible-items-using-cascades-and-qml/#comments</comments>
		<pubDate>Thu, 03 Jan 2013 19:37:04 +0000</pubDate>
		<dc:creator>btafel</dc:creator>
				<category><![CDATA[Native SDK Development]]></category>
		<category><![CDATA[custom items]]></category>
		<category><![CDATA[QML]]></category>
		<category><![CDATA[sample]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=12884</guid>
		<description><![CDATA[Expandable Item on an Expandable Framework One of the great things about jQuery mobile and other web technologies is that you can find a lot of components and examples out there. Almost every single type of visual element can be found online and there is no need to build it yourself. This is kind of [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=12884&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><strong>Expandable Item on an Expandable Framework</strong></p>
<p>One of the great things about jQuery mobile and other web technologies is that you can find a lot of components and examples out there. Almost every single type of visual element can be found online and there is no need to build it yourself. This is kind of the opposite of the native environment, where most of the times you need to build your own components; this commonly ends with taking a different direction in order to avoid that path. But with Cascades and QML, that’s old news.</p>
<p>Today we were asked if we have a QML component that behaves like the <a href="http://jquerymobile.com/test/docs/content/content-collapsible.html" target="_new">Collapsible on jQuery</a>. And the answer is no &#8211; unless you wait for 10 minutes and you build it yourself. Yes, it only took me 10 minutes to have that component ready to be used by anybody within Cascades.</p>
<p>So, let’s see how that happened.</p>
<p>First of all I created a QML file called ExpandableItem.qml. I created on a separated file so we can then reuse the code on any screen within the application.</p>
<p>Second step was to include the visual components. In this case, I included a Button and a Label:</p>
<pre>    Button {
        id: btnHeader
        text: "default header"
    }
    Label {
        id: lblBody
        text: "default body"
    }</pre>
<p><span id="more-12884"></span></p>
<p>This will give us the two components we need to build our new expandable component. Then I added some styling:</p>
<pre>    Button {
        id: btnHeader
        text: "default header"
        preferredWidth: maxWidth
    }
    Label {
        id: lblBody
        text: "default body"
        textStyle.fontStyle: FontStyle.Italic
    }</pre>
<p>And this was the first result we got:</p>
<p><img class="aligncenter size-full wp-image-12886" alt="TITLE_IMAGE" src="http://rimdevblog.files.wordpress.com/2013/01/expandable-item-1.jpg?w=600&#038;h=305" width="600" height="305" /></p>
<p>After defining our components, it was then time to define our properties, which allows us to interact with the UI component. In this case, we needed at least these ones to control the basic behavior:</p>
<pre>    property alias headerText: btnHeader.text
    property alias bodyText: lblBody.text
    property alias bodyVisible: lblBody.visible
    property string collapseImage
    property string expandImage</pre>
<p>I said “at least” because you can include as many properties you want to tweak your inside components. These are the basics to control the behavior of the expandable component. You can set the default imageSource of your button by including this line on your Button element:</p>
<pre>        imageSource: collapseImage</pre>
<p>It was then time to include our user interaction scripts. This allowed the user to interact with the component, and it reflects the user’s will.</p>
<p>I included two pieces of code:</p>
<p>a) for handling the click event on the Button:</p>
<pre>        onClicked: {
            if (bodyVisible) {
                lblBody.visible = false;
                btnHeader.imageSource = expandImage;
            } else {
                lblBody.visible = true;
                btnHeader.imageSource = collapseImage;
            }
        }</pre>
<p>b) to handle the change of the visibility of the body text:</p>
<pre>    onBodyVisibleChanged: {
        if (bodyVisible) {
            btnHeader.imageSource = collapseImage;
        } else {
            btnHeader.imageSource = expandImage;
        }
    }</pre>
<p>And this is what our new UI component looks like:</p>
<p style="text-align:center;"><img alt="" src="http://rimdevblog.files.wordpress.com/2013/01/expandable-item-2.jpg?w=280" width="280" /> <img alt="" src="http://rimdevblog.files.wordpress.com/2013/01/expandable-item-3.jpg?w=280" width="280" /></p>
<p>Now it is time to use it! And it is as easy as this, for example:</p>
<pre>        ExpandableItem {
            headerText: "click to expand"
            bodyText: "this is my custom body text"
            expandImage: "asset:///images/expand.png";
            collapseImage: "asset:///images/collapse.png";
            bodyVisible: false
        }</pre>
<p>And you will see this:</p>
<p><img class="aligncenter size-full wp-image-12889" alt="" src="http://rimdevblog.files.wordpress.com/2013/01/expandable-item-4.jpg?w=411&#038;h=56" width="411" height="56" /></p>
<p>Or, you can have the body displayed by default:</p>
<pre>        ExpandableItem {
            headerText: "click to expand"
            bodyText: "this is my custom body text"
            expandImage: "asset:///images/expand.png";
            collapseImage: "asset:///images/collapse.png";
            bodyVisible: true
        }</pre>
<p>With this as a result:</p>
<p><img class="aligncenter size-full wp-image-12890" alt="" src="http://rimdevblog.files.wordpress.com/2013/01/expandable-item-5.jpg?w=411&#038;h=104" width="411" height="104" /></p>
<p>As you can see, it is easy to create your custom components and replicate some standard logic out there. Keeping in mind the fact that these UI components are Native components, I think this is a big deal!</p>
<p>This example can be found on <a href="https://github.com/blackberry/Cascades-Community-Samples/tree/master/ExpandableSample" target="_blank">our Github page</a>.</p>
<p>If you have Cascades questions, please don’t hesitate to ping me on Twitter at <a href="http://twitter.com/bryantafel" target="_new">@bryantafel</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/12884/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/12884/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=12884&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2013/01/how-to-make-collapsible-items-using-cascades-and-qml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/01a58649dedc793ca2c840470f5af775?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">btafel</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2013/01/expandable-item-1.jpg" medium="image">
			<media:title type="html">TITLE_IMAGE</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2013/01/expandable-item-2.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/01/expandable-item-3.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/01/expandable-item-4.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/01/expandable-item-5.jpg" medium="image" />
	</item>
		<item>
		<title>Integrating NFC into your BlackBerry 10 Application</title>
		<link>http://devblog.blackberry.com/2012/10/blackberry-10-app-nfc/</link>
		<comments>http://devblog.blackberry.com/2012/10/blackberry-10-app-nfc/#comments</comments>
		<pubDate>Thu, 25 Oct 2012 15:34:13 +0000</pubDate>
		<dc:creator>mdwrim</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[BlackBerry 10]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[Near Field Communication]]></category>
		<category><![CDATA[nfc]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[use case]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=11782</guid>
		<description><![CDATA[Guest post from John Murray &#8211; Ed. You know, working in the Developer Relations team at Research In Motion® (RIM®), you get to get to play around with some fun stuff. Recently, Near Field Communication (NFC) has been exercising my brain cells. Some of you may be familiar with the NFC-related articles and code samples [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=11782&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><i>Guest post from John Murray &#8211; Ed.</i></p>
<p>You know, working in the Developer Relations team at Research In Motion® (RIM®), you get to get to play around with some fun stuff. Recently, Near Field Communication (NFC) has been exercising my brain cells. Some of you may be familiar with the NFC-related articles and code samples that I’ve co-authored with my co-conspirator, Martin Woolley (<a href="http://twitter.com/mdwrim" target="_new">@mdwrim</a>), which you can find listed in our <a href="http://supportforums.blackberry.com/t5/Java-Development/NFC-Article-and-Code-Index/ta-p/1538775" target="_new">NFC Article and Code index</a>.</p>
<p>Now, whenever you mention NFC in a conversation, people invariably think of payments. Using NFC to make secure payments is perhaps the most obvious use case. However, when I think of NFC I tend to think of workflows as well. “Workflows,” you say? What do you mean?</p>
<p>OK, let’s think about it anecdotally. How many times have you had the challenge of transcribing some data from an external source to your handset whilst holding a bag and trying to hold a conversation at the same time? How many times have you tried to share information on your handset with someone else and had to struggle with inputting email addresses whilst doing three other things at the same time? These use cases are examples of Workflows, or Business Processes, that stumble on the point of having to accommodate more “human” interaction than is really necessary. NFC can be used to help streamline simple workflows that involve human interactions on mobile devices and ultimately help achieve efficiencies.</p>
<p><span id="more-11782"></span></p>
<p>So, having thought about this and how to demonstrate a simple but realistic use case (whilst also having some fun), we came up with the concept of the “Fun Run”.</p>
<p>Suppose you’re taking part in a charity “Fun Run” – not quite a marathon but something shorter for fun. The race organizers have developed a simple mobile application to allow you to register for the event and have placed NFC Tags in the starting and finishing areas. As you start you tap on one of the tags, your race timer is started as well as notifying the organizers that you have begun. When you pass the finish line, simply tap on one of the tags in the Finish area to stop your timer and notify the organizers of your finishing time!</p>
<p>In between the start and finish, there may be Way Points with NFC Reader devices that can be used to register intermediate times as the runner passes these points. Tap the handset to the NFC Reader and receive confirmation that the timing data has been transferred successfully.</p>
<p>OK, maybe it’s not 100% realistic, but as an example it is sufficient to demonstrate how a workflow process that involves having to record start and finish times and tracking progress can be made more efficient using NFC. The key learning point is to understand how integrating NFC technology into your application can be used to achieve efficiencies in similar processes.</p>
<h3><strong>The Applications</strong></h3>
<p>Let’s take a look at how we implemented this simple example using BlackBerry® 10 and BlackBerry® 7 NFC capable devices. There are really three use cases:</p>
<p>1. Tap your handset against an NFC tag at the start of the race to start your race timer.<br />
2. Tap your handset against NFC readers at intermediate waypoints during the race to transfer your current race timer data to an application that manages the reader.<br />
3. Tap your handset against an NFC tag at the end of the race to stop your race timer.</p>
<h3><strong>Acting on External Tag Events</strong></h3>
<p>To implement the first and last use case, we decided to provide two NFC tags that had specific NDEF messages as their content. There would be one tag that would start the timer at the start of the race and one tag that would stop the timer at the end of the race.</p>
<p>Specifically the data in the two tags is:</p>
<p><strong>1. Tag used to start the timer:</strong></p>
<p>NDEF TNF = External ( integer value 4 )<br />
Type = &#8220;my.rim.com:myrecordtype&#8221;<br />
Payload = &#8220;start&#8221;</p>
<p><strong>2. Tag used to stop the timer:</strong></p>
<p>NDEF TNF = External ( integer value 4 )<br />
Type = &#8220;my.rim.com:myrecordtype&#8221;<br />
Payload = &#8220;stop&#8221;</p>
<p>Why use this data? Well, firstly we choose an NDEF TNF (Type Name Format) for the NDEF Message because it allows us to define custom tag content that won’t clash with standard tag message types such as Smart Poster (“Sp”) or URL (“U”) or Text (“T”). We want to make sure that when one of these tags is presented, our application, and our application alone, is launched to process the tag.</p>
<p>Secondly, we choose a “Type” of &#8220;<strong>my.rim.com:myrecordtype</strong>&#8220;. Within the context of an External TNF record the Type can be arbitrary, but in order to prevent clashes with other organizations’ custom tag formats, we use the DNS naming scheme to set the namespace of the tag as “<strong>my.rim.com</strong>” to establish it as a RIM NDEF message. We further qualify it with a specific sub-type of “<strong>myrecordtype</strong>” since an organization may define a whole family of custom tag formats for its own use.</p>
<p>So, these settings ensure that these tags will only make sense to our application and not overlap with tags form elsewhere. The “Payload” of the two tags differs in that one has the string “<strong>start</strong>” and the other has the string “<strong>stop</strong>” to mark them as ones to be used to start and stop the timers respectively.</p>
<p>In the case of BlackBerry 10, our application registered with the Invocation Framework through the stanza in its “<strong>bar-descriptor.xml</strong>” file as shown in Figure 1. The “<strong>uris</strong>” attribute of the “<strong>&lt;property &#8230; /&gt;</strong>” tag has been set to the value “<strong>ndef://4/my.rim.com/myrecordtype</strong>” which a URI format specification of the two tags just described above.</p>
<pre>...
&lt;invoke-target id="com.example.NfcRaceTimeWay"&gt;
    &lt;type&gt;APPLICATION&lt;/type&gt;
    &lt;filter&gt;
        &lt;action&gt;bb.action.OPEN&lt;/action&gt;
        &lt;mime-type&gt;application/vnd.rim.nfc.ndef&lt;/mime-type&gt;
        &lt;property var="uris" value="ndef://4/my.rim.com/myrecordtype"/&gt;
    &lt;/filter&gt;
&lt;/invoke-target&gt;
...</pre>
<p style="text-align:center;">Figure 1 Registering for tag types in BlackBerry 10</p>
<p>When a “start” or “stop” tag is presented to the handset, then our application is launched if it’s not already running, and the tag contents are handled as shown in Figure 2 &#8212; where the payload of “start” or “stop” is extracted once we’ve verified that it’s of the correct type.</p>
<pre>...
void NfcListener::receivedInvokeRequest(const bb::system::InvokeRequest&amp; request) {

    QByteArray data = request.data();
    QtMobilitySubset::QNdefMessage ndefMessage = QtMobilitySubset::QNdefMessage::fromByteArray(data);

    handleNdefRequest(ndefMessage);
}

void NfcListener::handleNdefRequest(const QtMobilitySubset::QNdefMessage ndefMessage) {

    QList::const_iterator ndefRecord;

    for ( ndefRecord = ndefMessage.begin(); ndefRecord != ndefMessage.end(); ndefRecord++) {
        if (ndefRecord-&gt;typeNameFormat() == QtMobilitySubset::QNdefRecord::ExternalRtd) {
            if (QString(ndefRecord-&gt;type()).compare("my.rim.com:myrecordtype") == 0 ) {
                emit raceTagDetected(QString(ndefRecord-&gt;payload()));
            }
        }
    }
}
...</pre>
<p style="text-align:center;">Figure 2 Handling a Start or Stop tag in BlackBerry 10</p>
<p>In the case of BlackBerry 7, registration is achieved in Java® by registering a listener for the specific NDEF message type as shown in Figure 3.</p>
<pre>...
    nfcManager = ReaderWriterManager.getInstance();
    nfcManager.addNDEFMessageListener(listener, NDEFRecord.TNF_EXTERNAL, "my.rim.com:myrecordtype", true);
...</pre>
<p style="text-align:center;">Figure 3 Registering for tag types in BlackBerry 7</p>
<p>A similar behaviour is achieved for BlackBerry 7 through the implementation of the “<strong>onNDEFMessageDetected()</strong>” method of the “<strong>NDEFMessageListener</strong>” interface as shown in Figure 4.</p>
<pre>...
    public void onNDEFMessageDetected(NDEFMessage msg) {
        NDEFRecord[] records = msg.getRecords();
        int numRecords = records.length;
        if(numRecords &gt; 0) {
            byte[] payloadBytes = records[0].getPayload();
            try {
                String ascii_payload = new String(payloadBytes,"US-ASCII");
                Utilities.log("XXXX payload="+ascii_payload);
                if (ascii_payload.equals("start")) {
                    startTimer();
                }
                if (ascii_payload.equals("stop")) {
                    stopTimer();
                }
            } catch(UnsupportedEncodingException e) {
                Utilities.log("XXXX "+e.getClass().getName()+":"+e.getMessage());
            }
        }

    }

...</pre>
<p style="text-align:center;">Figure 4 Handling a Start or Stop tag in BlackBerry 7</p>
<p>So, what we’ve achieved here is the ability to use an external NFC tag to trigger a process in our application. In this case it’s simply the starting and stopping of a timer, but it could be extended quite easily to, say, call a web service and integrate the event into a larger workflow process.</p>
<p>What does this look like in practice? Well, here’s a short video of the BlackBerry 10 application in action:</p>
<p style="text-align:center;"><span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='480' height='360' src='http://www.youtube.com/embed/QZ5nABZcFuo?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe></span></p>
<p style="text-align:center;">[ <a href="http://www.youtube.com/watch?v=QZ5nABZcFuo&amp;feature=youtu.be" target="_new">YouTube link for mobile viewing</a> ]</p>
<h3><strong>Virtual Tag Emulation</strong></h3>
<p>Let’s get back to the original use cases. To implement the second one, we decided to have the BlackBerry handset emulate a virtual tag and allow the contents of the virtual tag to be read by an external NFC reader.<br />
What format of tag should be emulated by the handset? This is what we chose:</p>
<p><strong>1. Virtual tag emulated by the application</strong></p>
<p>NDEF TNF = External ( integer value 4 )<br />
Type = &#8220;my.rim.com:myrecordtype&#8221;<br />
Payload = &#8220;hh:mm:ss&#8221;</p>
<p>a. That is the time displayed on the handset in:<br />
Hours (hh)<br />
Minutes (mm)<br />
Seconds (ss)</p>
<p>The type of the virtual tag is exactly the same as for the “start” and “stop” physical tags for the very same reasons, except that the payload is a representation of the current race timer value (“hh:mm:ss”) as displayed by the application.</p>
<pre>...
void NfcListener::startTagEmulation(const QString &amp;tagData) {
    nfc_ndef_record_t *ndefRecord = makeCustomRecord(QString("my.rim.com"), QString("myrecordtype"), tagData);
    if (_emulateNdefMessage) {
        CHECK(nfc_delete_ndef_message(_emulateNdefMessage, true));
        _emulateNdefMessage = 0;
    }
    CHECK(nfc_create_ndef_message(&amp;_emulateNdefMessage));
    CHECK(nfc_add_ndef_record(_emulateNdefMessage, ndefRecord));
    CHECK(nfc_start_ndef_tag_emulation(_emulateNdefMessage));
...</pre>
<p style="text-align:center;">Figure 5 BlackBerry 10 &#8211; starting virtual tag emulation</p>
<p>As shown in Figure 5, starting tag emulation in BlackBerry 10 is quite simple. It just involves calling “<strong>nfc_start_ndef_tag_emulation()</strong>”. In addition we can use BPS (BlackBerry Platform Services) to determine when a read on the virtual tag has been successful, as shown here in Figure 6:</p>
<pre>...
void NfcListener::handleNfcEvent(bps_event_t *event) {
    uint16_t code = bps_event_get_code(event);
    if (NFC_VIRTUAL_TAG_SELECTION_EVENT == code) {
        emit tagEmulationSelectEvent();
    } else if (NFC_VIRTUAL_TAG_LEFT_EVENT == code) {
        emit tagEmulationLeftEvent();
    } else if (NFC_VIRTUAL_TAG_READ_EVENT == code) {
        emit tagEmulationReadEvent();
    }
}
...</pre>
<p style="text-align:center;">Figure 6 BlackBerry 10 &#8211; stopping virtual tag emulation</p>
<p>So, what we’ve achieved here is the ability to transmit live information from an application in the BlackBerry handset in real time to an external application via an NFC reader. The external application simply displays the time displayed by the BlackBerry application, but it could easily be extended to integrate with some larger workflow process.</p>
<p>Take a look at the video here for a demonstration of this on BlackBerry 10:</p>
<p style="text-align:center;"><span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='480' height='360' src='http://www.youtube.com/embed/g58Xpnsqq4o?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe></span></p>
<p style="text-align:center;">[ <a href="http://www.youtube.com/watch?v=g58Xpnsqq4o&amp;feature=youtu.be" target="_new">YouTube link for mobile viewing</a> ]</p>
<p>If you’re interested, the virtual tag emulation functionality was tested using an NFC Reader attached to a PC controlled by a Python application using the “PyScard” (Python for Smart Cards) library available from <a href="http://pyscard.sourceforge.net/" target="_new">SourceForge.net</a>. (Python and Ruby are my favorite programming languages!)</p>
<p>The two versions of our NFC-enabled “Fun Run” applications are available with full source code from our GitHub repositories here:</p>
<p><a href="https://github.com/blackberry/Cascades-Community-Samples/tree/master/NfcRaceTimeWay" target="_new"><br />
https://github.com/blackberry/Cascades-Community-Samples/tree/master/NfcRaceTimeWay<br />
</a><br />
<a href="https://github.com/blackberry/Samples-for-Java/tree/master/NFC/NfcRaceTime7" target="_new"><br />
https://github.com/blackberry/Samples-for-Java/tree/master/NFC/NfcRaceTime7<br />
</a></p>
<p>Just in closing, it’s worth making one or two comments about the relative ease of developing applications to the same set of end user specifications in BlackBerry 10 Cascades™ versus BlackBerry 7 Java. I’ve been developing code in C/C++ for more years than I care to remember and for a shorter time in Java (but still since the language first saw the light of day), so I feel I’m qualified to make comparisons. I’ll be honest: I’ve found it much easier to develop applications using C/C++ and Cascades. The user interface elements are particularly easy to use, and I’ve found it possible to get a user interface up and running in Cascades much faster than I would have done in Java. It’s much easier to modify and extend since Cascades elements map directly to Qt/Cascades C++ classes and the SIGNAL() / SLOT() model makes it so easy to connect events to handlers.</p>
<p>I’m definitely sold on Cascades, Qt and C/C++!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/11782/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/11782/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=11782&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2012/10/blackberry-10-app-nfc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d86c7fdd0d15b754b2760af4536923b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mdwrim</media:title>
		</media:content>
	</item>
	</channel>
</rss>
