<?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; communication</title>
	<atom:link href="http://devblog.blackberry.com/tag/communication/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.blackberry.com</link>
	<description></description>
	<lastBuildDate>Wed, 22 May 2013 19:49:17 +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; communication</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>Creating a YouTube viewer with the BlackBerry 6 Communication API</title>
		<link>http://devblog.blackberry.com/2011/01/communication-api-2/</link>
		<comments>http://devblog.blackberry.com/2011/01/communication-api-2/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 21:30:08 +0000</pubDate>
		<dc:creator>Tim W.</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Platform Services]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[blackberry 6]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=3030</guid>
		<description><![CDATA[How to utilize the Communication and Parsing API introduced in the BlackBerry® 6 OS to create a YouTube viewer.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=4001&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-3031" title="Communication API" src="http://rimdevblog.files.wordpress.com/2011/01/communication-api-screenshot4.png?w=360&#038;h=480" alt="" width="360" height="480" /></p>
<p>The Communication and Parsing API introduced in the BlackBerry® 6 OS probably doesn’t get as much attention as it really deserves. It has one of those names that could mean just about anything, but when I created a sample with it, I found it made many tasks simple – and I barely scratched the surface of what was possible.</p>
<p>You’ll find the API specification in the <a href="http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/io/messaging/package-summary.html" target="_new">net.rim.device.api.io.messaging</a> package, where you will see the significant set of interfaces and classes that provide all this functionality. The API breaks up communication into a few parts: The <a href="http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/io/messaging/Destination.html" target="_new">Destination</a> is the target for a connection, usually a URL, and you can send and receive <a href="http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/io/messaging/Message.html" target="_new">Message</a> objects through it. Destinations can block the execution thread, or not, and you can send messages without handling the response with a <a href="http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/io/messaging/FireAndForgetDestination.html" target="_new">FireAndForgetDestination</a>. A Destination can also be connected with a <a href="http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/io/messaging/MessageProcessor.html" target="_new">MessageProcessor</a>, which will parse the messages for you. Several processors are included in the API for common message formats like XML, JSON, RSS, and so on. Processors can be chained to support even more functionality. Finally, Messages can be retrieved as <a href="http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/io/messaging/MessageFuture.html" target="_new">MessageFutures</a>, and Destinations can be used to receive pushes and other incoming connections.</p>
<p><span id="more-4001"></span></p>
<p>Behind the scenes is even more great stuff, like message queuing, prioritization, and even support for inter-process communication. Before we get too buried in the details, I should point out that the BlackBerry 6 SDK includes a full sample application that shows how to do all of this. The sample I want to share with you today is an example using this new API to streamline development of a YouTube® client. With the proliferation of APIs like <a href="http://code.google.com/apis/youtube/getting_started.html" target="_new">YouTube’s Data API</a>, which offer ATOM and <a href="http://code.google.com/apis/youtube/2.0/developers_guide_jsonc.html" target="_new">JSON-C</a> (for more bandwidth saving) interfaces, many opportunities become quite accessible.</p>
<p><a href="http://supportforums.blackberry.com/t5/Java-Development/How-to-Create-a-YouTube-viewer-with-the-BlackBerry-6/ta-p/744251" target="_new">Full sample code</a> is included so you can check it out, but let’s look at some of the Communication API in action. The destination is the YouTube Data server with several basic query parameters:</p>
<div class="sample">
<pre>BlockingSenderDestination destination = DestinationFactory.createBlockingSenderDestination(_context,
URI.create(buildQueryURL(query, index, max)), _processor);</pre>
</div>
<p>Where my URL is built from a base, and I’m just appending the search query string and variables to return a particular section of the feed, I end up with a URL like so:</p>
<div class="sample">
<pre>"http://gdata.youtube.com/feeds/mobile/videos?v=2&amp;fields=entry[link/@rel=%27http://gdata.youtube.com/schemas/2007%23mobile%27]&amp;format=6&amp;q=blackberry.com/developers&amp;start-index=1&amp;max-results=10";</pre>
</div>
<p>The query I’ve used restricts the response somewhat to a mobile-friendly version, including filtering out any videos that don’t have a mobile video link – a useful feature for mobile clients that could be <a href="http://code.google.com/apis/youtube/2.0/developers_guide_protocol_partial.html" target="_new">expanded on in this sample</a>. I’ve also included a MessageProcessor to handle the output; in this case, it’s an <a href="http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/io/parser/xml/XMLHashtableMessageProcessor.html" target="_new">XMLHashtableMessageProcessor</a>, which nicely converts the ATOM response into a simple Hashtable, so I can do things like pulling all the titles out into a String array:</p>
<div class="sample">
<pre>String[] titles = contents.getStringArray("/feed/entry/title");</pre>
</div>
<p>Once I’ve grabbed all the details I care about, I can send the results back to the screen for displaying. However, the feed response contains a URL for the thumbnails, so I need to download that as well. This is a neat opportunity to use non-blocking destinations and update the display when the thumbnails arrive:</p>
<div class="sample">
<pre>NonBlockingSenderDestination destination = DestinationFactory.createNonBlockingSenderDestination(_context,
					URI.create(url), this);
destination.send();</pre>
</div>
<p>Those requests are fired off through the API and I’ve got a <a href="http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/io/messaging/MessageListener.html" target="_new">MessageListener</a> waiting for them, which will take the data and inform the screen it can update the image from the placeholder:</p>
<div class="sample">
<pre>public void onMessage(Destination destination, Message message) {
if (message instanceof ByteMessage) {
		byte[] results = ((ByteMessage) message).getBytePayload();
		EncodedImage image = EncodedImage.createEncodedImage(results, 0, -1);
		... //send the image to the Screen
		destination.destroy();
	}
}</pre>
</div>
<p><a href="http://supportforums.blackberry.com/t5/Java-Development/How-to-Create-a-YouTube-viewer-with-the-BlackBerry-6/ta-p/744251" target="_new">Give the sample a look</a> and check out the API in more depth to see how you can put it to work for you. We’ll follow this up later with a more detailed sample showcasing the advanced features of both YouTube’s Data API and the BlackBerry® Communication API.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/4001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/4001/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=4001&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2011/01/communication-api-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d4af90af66399bef37f445ec81aba64a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">timwin1</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2011/01/communication-api-screenshot4.png" medium="image">
			<media:title type="html">Communication API</media:title>
		</media:content>
	</item>
	</channel>
</rss>
