<?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/"
	>

<channel>
	<title>josecgomez.com &#187; google</title>
	<atom:link href="http://www.josecgomez.com/tag/google/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.josecgomez.com</link>
	<description>The random thoughts of an IT professional.</description>
	<lastBuildDate>Wed, 18 Jan 2012 13:40:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CR48 Day 5</title>
		<link>http://www.josecgomez.com/2011/02/02/cr48-day-5/</link>
		<comments>http://www.josecgomez.com/2011/02/02/cr48-day-5/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 12:11:12 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Chrome OS]]></category>
		<category><![CDATA[CR48]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Google Docs]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=651</guid>
		<description><![CDATA[Nothing out of the ordinary today, browsed the web / Facebook and everything worked OK. Worth noting that I attempted to download / open a word document from Blackboard for school and had a bit of difficulty doing it. When clicking on a word document online I would expect it to be pushed out to Google Docs for reading [...]]]></description>
			<content:encoded><![CDATA[<p>Nothing out of the ordinary today, browsed the web / Facebook and everything worked OK. Worth noting that I attempted to download / open a word document from Blackboard for school and had a bit of difficulty doing it. When clicking on a word document online I would expect it to be pushed out to Google Docs for reading but instead you are prompted with a download dialog box.</p>
<p>Once you download the doc, if you attempt to open it, it says &#8220;File Not Recognized&#8221;. So you have to navigate to Google Docs, and upload the file manually. I would like for the CR48 to automatically take you to the Google Docs and upload the doc directly from the link I click.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2011/02/02/cr48-day-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CR48 Day 4</title>
		<link>http://www.josecgomez.com/2011/02/01/cr48-day-4/</link>
		<comments>http://www.josecgomez.com/2011/02/01/cr48-day-4/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 12:15:49 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Chrome OS]]></category>
		<category><![CDATA[CR48]]></category>
		<category><![CDATA[Docs]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=648</guid>
		<description><![CDATA[I had class tonight for the first time since I got the CR48, I took it with me and decided to take all my notes using it. To my surprise it was very easy, I opened up Google Docs and started taking notes, the class was Data Mining and half way into it I had [...]]]></description>
			<content:encoded><![CDATA[<p>I had class tonight for the first time since I got the CR48, I took it with me and decided to take all my notes using it. To my surprise it was very easy, I opened up Google Docs and started taking notes, the class was Data Mining and half way into it I had the need to copy down some formulas. I found out that Google Docs has a formulas toolbar with just about any symbol / function you may need.</p>
<p>Class was a breeze and I really enjoyed taking notes, a couple of times I got disconnected from the doc but the CR48 seemed to handle it OK. The only negative I had was that at some point the touch-pad decided to go into highlight mode and it took me a few minutes of fiddling to get it back to normal. Overall class was a very pleasant experience with the CR48 another WIN</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2011/02/01/cr48-day-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CR48 Day 3</title>
		<link>http://www.josecgomez.com/2011/01/31/cr48-day-3/</link>
		<comments>http://www.josecgomez.com/2011/01/31/cr48-day-3/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 12:55:37 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Chrome OS]]></category>
		<category><![CDATA[CR48]]></category>
		<category><![CDATA[Fish]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=641</guid>
		<description><![CDATA[Today was Sunday and didn&#8217;t get to do much, I made whole trout and used the CR48 to lookup how to fillet it. It worked ok and accomplished what I needed, another win for the CR48 httpv://www.youtube.com/watch?v=NZxe-2rtOGo]]></description>
			<content:encoded><![CDATA[<p>Today was Sunday and didn&#8217;t get to do much, I made whole trout and used the CR48 to lookup how to fillet it. It worked ok and accomplished what I needed, another win for the CR48<br />
<a href="http://www.youtube.com/watch?v=NZxe-2rtOGo">httpv://www.youtube.com/watch?v=NZxe-2rtOGo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2011/01/31/cr48-day-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chrome OS Day 2</title>
		<link>http://www.josecgomez.com/2011/01/30/chrome-os-day-2/</link>
		<comments>http://www.josecgomez.com/2011/01/30/chrome-os-day-2/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 04:17:14 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Chrome OS]]></category>
		<category><![CDATA[CR48]]></category>
		<category><![CDATA[Chome OS]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[PickNic]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=629</guid>
		<description><![CDATA[Today was the second day with my CR 48, as promised I used it exclusively throughout the day to get anything done. I attempted to watch Twit Live with it however the feed was choppy and the audio was off sync with the video. I moved on to BOL (Buzz Out Loud) and had the same problem, [...]]]></description>
			<content:encoded><![CDATA[<p>Today was the second day with my CR 48, as promised I used it exclusively throughout the day to get anything done. I attempted to watch <a href="http://live.twit.tv/">Twit Live</a> with it however the feed was choppy and the audio was off sync with the video. I moved on to BOL (Buzz Out Loud) and had the same problem, I was able to downgrade the stream to Low Def and it helped a bit but any time I asked the CR48 to give me full screen video the image got choppy and the audio degraded.</p>
<p>Later in the afternoon I took some pictures of a painting I drew and had the need to make some adustments to the image I used Picknic an online photo editing app to make the changes needed. The first problem I had was trying to get the images onto the machine. Although the CR48 comes with a USB Port and an SD Card slot pluggin media into either of these did not make a difference.</p>
<p>After poking around the Internet I had found out that to enable file browsing I had to enable a special flag located in about:flags. Once I enabled advanced file access I was able to see the SDK and to upload the picture to <a href="http://www.picnik.com/app/">Picknic</a>. I successfully edited the picture and was able to upload it to Facebook.</p>
<p style="text-align: center;">
<p>So far so good, I did not enjoy the video playing but I think it has more to do with the hardware in the CR48 than the OS.</p>
<div>

<a href="http://www.josecgomez.com/wordpress/wp-content/gallery/oil-paintings/FirstLight.png" title="First Light 1/29/2011 " class="shutterset_singlepic26" >
	<img class="ngg-singlepic" src="http://www.josecgomez.com/wordpress/wp-content/gallery/cache/26__200x150_FirstLight.png" alt="First Light" title="First Light" />
</a>

</div>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2011/01/30/chrome-os-day-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CR48 Day 1</title>
		<link>http://www.josecgomez.com/2011/01/29/cr48-day-1/</link>
		<comments>http://www.josecgomez.com/2011/01/29/cr48-day-1/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 04:54:22 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Chrome OS]]></category>
		<category><![CDATA[CR48]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=623</guid>
		<description><![CDATA[Yesterday to my surprise I received a CR48 from Google; for those not familiar with what this is, its a prototype laptop that Google sent out to a group of people for testing their new cloud operating system Chrome OS. As a tester I made the commitment of using the CR48 &#8220;exclusively&#8221; for 30 days. [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-medium wp-image-626 alignright" title="ChromeOS" src="http://www.josecgomez.com/wordpress/wp-content/uploads/2011/01/ChromeOS-300x225.jpg" alt="" width="300" height="225" /></p>
<p>Yesterday to my surprise I received a CR48 from Google; for those not familiar with what this is, its a prototype laptop that Google sent out to a group of people for testing their new cloud operating system <a href="http://www.google.com/chromeos/">Chrome OS</a>.</p>
<p>As a tester I made the commitment of using the CR48 &#8220;exclusively&#8221; for 30 days. The reason why the exclusively is in quotes is because I can&#8217;t reasonably use it for programming windows forms application, something that is required of me at work. But for any other activity I will attempt to use the cloud based CR48.</p>
<p>Today was the first full day I had with the laptop, I was able to transition my Google Apps account to be used with the laptop and I was able to get all my Google services loaded into it.</p>
<p>I experienced my first problem in the afternoon while watching a YouTube video, the sound started making static noises and became unbearable. Apparently this is a known issue. Besides this I did not encounter I that I could not do. So far so good.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2011/01/29/cr48-day-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GOLang Hello World!</title>
		<link>http://www.josecgomez.com/2010/09/29/golang-hello-world/</link>
		<comments>http://www.josecgomez.com/2010/09/29/golang-hello-world/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 15:25:39 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[GOlang]]></category>
		<category><![CDATA[Golang]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=590</guid>
		<description><![CDATA[Hello World in Golang]]></description>
			<content:encoded><![CDATA[<p>The Obligatory Hello World for GO.</p>
<p>I won&#8217;t go int too much detail at the moment, in future posts I will make sure to revisit everything shown here. This is more or less a test</p>
<script><html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.0.4</center>
</body>
</html>
</script><div style='margin-bottom:1em;padding:0;'><noscript><code><pre style='overflow:auto;margin:0;padding:0;border:1px solid #DDD;'>&lt;html&gt;
&lt;head&gt;&lt;title&gt;301 Moved Permanently&lt;/title&gt;&lt;/head&gt;
&lt;body bgcolor=&quot;white&quot;&gt;
&lt;center&gt;&lt;h1&gt;301 Moved Permanently&lt;/h1&gt;&lt;/center&gt;
&lt;hr&gt;&lt;center&gt;nginx/1.0.4&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre></code></noscript></div>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2010/09/29/golang-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GOlang System Programming</title>
		<link>http://www.josecgomez.com/2010/09/08/go-system-programming/</link>
		<comments>http://www.josecgomez.com/2010/09/08/go-system-programming/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 19:13:37 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[GO!]]></category>
		<category><![CDATA[Golang]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[System Language]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=575</guid>
		<description><![CDATA[GOlang takes a fresh spin at something we are all familiar with, it does it class and performance. I have recently had the chance to delve into the intricacies of GO and I have decided to dedicated part of my blog to it as a resource for future programmers.]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Last year Google introduced Golang (GO) a system programming language.</p>
<p style="text-align: left;">&#8220;No major systems language has emerged in over a decade, but over that time the computing landscape has changed tremendously&#8221;</p>
<p style="text-align: left;">GOlang takes a fresh spin at something we are all familiar with, it does it with class and performance. I have recently had the chance to delve into the intricacies of GO for class and decided to dedicated part of my blog to it as a resource for future programmers.</p>
<p style="text-align: left;">I have acquired the ONLY GO Programming book available and will be posting a review shortly. I will also start to develop a library of simple examples to help everyone out!</p>
<p style="text-align: left;">GO&#8217;s official site is located at <a href="http://golang.org/">http://golang.org</a></p>
<p style="text-align: left;">The book which has been facilitated to me can be found at <a href="http://www.goprogrammingbook.com/">http://www.goprogrammingbook.com/</a></p>
<p style="text-align: left;"><a href="http://www.goprogrammingbook.com/"></a><img title="GO Lang" src="http://golang.org/doc/logo-153x55.png" alt="GO Lang" width="153" height="55" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2010/09/08/go-system-programming/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The hidden cost of Google&#8217;s Pacman</title>
		<link>http://www.josecgomez.com/2010/05/25/the-hidden-cost-of-googles-pacman/</link>
		<comments>http://www.josecgomez.com/2010/05/25/the-hidden-cost-of-googles-pacman/#comments</comments>
		<pubDate>Tue, 25 May 2010 12:30:34 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Views]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[pacman]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=538</guid>
		<description><![CDATA[As you probably saw either on Google, my site or any of the thousands of sites that reported it. In order to celebrate Pacmas 30th anniversary the folks at our favorite company Google, made their first ever animated doodle which let you play Pacman with its original sounds and levels. The blog at rescuetime.com has speculated that this awesome [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.josecgomez.com/wordpress/wp-content/uploads/2010/05/pacman.png"><img class="aligncenter size-full wp-image-541" title="pacman" src="http://www.josecgomez.com/wordpress/wp-content/uploads/2010/05/pacman.png" alt="" width="554" height="187" /></a></p>
<p>As you probably saw either on Google, my site or any of the thousands of sites that reported it. In order to celebrate Pacmas 30th anniversary the folks at our favorite company Google, made their first ever animated doodle which let you play Pacman with its original sounds and levels. The blog at <a href="http://blog.rescuetime.com">rescuetime.com</a> has speculated that this awesome little stunt may have cost us $298,803,988.</p>
<blockquote><p>If we take <a href="http://www.wolframalpha.com/input/?i=google+traffic">Wolfram Alpha at its word</a>, Google had about 504,703,000 unique visitors on May 23. If we assume that our userbase is representative, that means:</p>
<ul>
<li>Google Pac-Man consumed 4,819,352 hours of time (beyond the 33.6m daily man hours of attention that Google Search gets in a given day)</li>
<li>$120,483,800 is the dollar tally, If the average Google user has a COST of $25/hr (note that cost is 1.3 – 2.0 X pay rate).</li>
<li>For that same cost, you could hire all 19,835 google employees, from Larry and Sergey down to their janitors, and get 6 weeks of their time. Imagine what you could build with that army of man power.</li>
<li>$298,803,988 is the dollar tally if all of the Pac-Man players had an approximate cost of the average Google employee.</li>
</ul>
</blockquote>
<p>I don&#8217;t believe this numbers to be anywhere near accurate and I still appreciate and enjoyed thoroughly what Google did. I wonder if anyone ever calculated how much money we loose on Facebook every day?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2010/05/25/the-hidden-cost-of-googles-pacman/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Pacman Doodle!</title>
		<link>http://www.josecgomez.com/2010/05/21/google-packman-doodle/</link>
		<comments>http://www.josecgomez.com/2010/05/21/google-packman-doodle/#comments</comments>
		<pubDate>Fri, 21 May 2010 15:36:49 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Views]]></category>
		<category><![CDATA[awesome]]></category>
		<category><![CDATA[doodle]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[packman]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=514</guid>
		<description><![CDATA[If you visit Google today you are greeted by the standard Google doodle. Today it represents the 30th anniversary of Pack Man As usual Google has chosen to use, it&#8217;s logo to honor what could be considered one of the biggest games of all times. However, this time there is a twist. If you stay [...]]]></description>
			<content:encoded><![CDATA[<p>If you visit <a href="http://www.google.com">Google</a> today you are greeted by the standard Google doodle. Today it represents the 30th anniversary of Pack Man</p>
<p><img class="aligncenter size-medium wp-image-515" title="packman" src="http://www.josecgomez.com/wordpress/wp-content/uploads/2010/05/packman-300x93.png" alt="" width="300" height="93" /></p>
<p>As usual Google has chosen to use, it&#8217;s logo to honor what could be considered one of the biggest games of all times. However, this time there is a twist. If you stay in the page long enough and click around. The doodle comes alive allowing you to control the pacman and play the game with the original sounds and all.</p>
<blockquote><p>The interactive doodle &#8212; a first for Google &#8212; is the brainchild of senior user experience designer Marcin Wichary, whose earliest exposure to <em>Pac-Man </em>came at age five while traveling across his native Poland with his father, a game technician, to repair arcade machines. Wichary worked with Google doodler (yes, it&#8217;s a real job) Ryan Germick to create the finished design. <a href="http://www.joystiq.com/2010/05/21/google-celebrates-pac-mans-30th-with-playable-logo/">more&#8230;</a></p>
</blockquote>
<p>This right here, is why I love Google!</p>
<p><center></p>
<p>
<p><a href="http://www.youtube.com/watch?v=abuLFOoBAbI">www.youtube.com/watch?v=abuLFOoBAbI</a></p>
</p>
<p></center></p>
<p>Update: Google has just posted an entry on <a href="http://googleblog.blogspot.com/2010/05/celebrating-pac-mans-30th-birthday.html">their blog</a> about the pacman game and its significance.</p>
<blockquote><p>When I was growing up, my dad had the best job I could possibly imagine: he was an arcade game and pinball technician. For me, that meant summer trips through Poland’s coastal cities with their seasonal arcade parlors; peeking inside cabinets to learn programming and engineering secrets; and—of course—free games!</p>
<p>One of my favorites was <a href="http://en.wikipedia.org/wiki/Pac-Man">PAC-MAN</a>, whose popularity transcended the geopolitical barriers of that time. During the heyday of space shooters, <a href="http://en.wikipedia.org/wiki/T%C5%8Dru_Iwatani">Tōru Iwatani</a>’s creation stood out as one of the first video games aimed at a broader audience, with a cute story of pizza-shaped character gobbling dots in a maze, colorful (literally!) characters, friendly design, very little violence and everlasting fun.</p>
<p>Today, on PAC-MAN’s 30th birthday, you can rediscover some of your 8-bit memories—or meet PAC-MAN for the first time—through our first-ever playable Google doodle. To play the game, go to <a href="http://www.google.com/">google.com</a> during the next 48 hours (because it’s too cool to keep for just one day) and either press the “Insert Coin” button or just wait for a few seconds.</p>
<p>Google doodler Ryan Germick and I made sure to include PAC-MAN’s original game logic, graphics and sounds, bring back ghosts’ individual personalities, and even recreate original bugs from this 1980’s masterpiece. We also added a little <a href="http://en.wikipedia.org/wiki/Easter_egg_(media)">easter egg</a>: if you throw in another coin, Ms. PAC-MAN joins the party and you can play together with someone else (PAC-MAN is controlled with arrow keys or by clicking on the maze, Ms. PAC-MAN using the WASD keys).</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2010/05/21/google-packman-doodle/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Android accessing RESTFull Web Services using JSON</title>
		<link>http://www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/</link>
		<comments>http://www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 13:31:05 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Gson]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=379</guid>
		<description><![CDATA[I just finished a huge project for school using the Google Android OS. The biggest hurdle I had to jump through we getting android to successfully talk to web services. I have put together a set of classes and procedures to do so that make it easy and reliable. I have taken some code from [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished a huge project for school using the Google Android OS. The biggest hurdle I had to jump through we getting android to successfully talk to web services. I have put together a set of classes and procedures to do so that make it easy and reliable. I have taken some code from here and there and adapted my own. It was a while ago so I don&#8217;t recall where I found it all. For this example I am going to be using the web service  <a href="http://www.sumasoftware.com/alerts/GetAlerts.php">http://www.sumasoftware.com/alerts/GetAlerts.php</a> to read the alerts.</p>
<p>The first thing you&#8217;ll need to download and add to your project is the google GSON library <a href="http://code.google.com/p/google-gson/issues/list">http://code.google.com/p/google-gson/downloads/list</a></p>
<p><a href="http://code.google.com/p/google-gson/issues/list"></a>Add the jar file to your android project as an external jar</p>
<p>Download the following WebService.java class in order to interact with the web service and add it to your project</p>
<p>
<pre class="brush: java; title: ; notranslate">
package josecgomez.com.android.dev.webservice;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.CookiePolicy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.google.gson.Gson;

public class WebService{

    DefaultHttpClient httpClient;
    HttpContext localContext;
    private String ret;

    HttpResponse response = null;
    HttpPost httpPost = null;
    HttpGet httpGet = null;
    String webServiceUrl;

    //The serviceName should be the name of the Service you are going to be using.
    public WebService(String serviceName){
        HttpParams myParams = new BasicHttpParams();

        HttpConnectionParams.setConnectionTimeout(myParams, 10000);
        HttpConnectionParams.setSoTimeout(myParams, 10000);
        httpClient = new DefaultHttpClient(myParams);
        localContext = new BasicHttpContext();
        webServiceUrl = serviceName;

    }

    //Use this method to do a HttpPost\WebInvoke on a Web Service
    public String webInvoke(String methodName, Map&lt;String, Object&gt; params) {

    	JSONObject jsonObject = new JSONObject();

    	for (Map.Entry&lt;String, Object&gt; param : params.entrySet()){
    		try {
    			jsonObject.put(param.getKey(), param.getValue());
			}
    		catch (JSONException e) {
    			Log.e(&quot;Groshie&quot;, &quot;JSONException : &quot;+e);
			}
    	}
        return webInvoke(methodName,  jsonObject.toString(), &quot;application/json&quot;);
    }

    private String webInvoke(String methodName, String data, String contentType) {
        ret = null;

        httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);

        httpPost = new HttpPost(webServiceUrl + methodName);
        response = null;

        StringEntity tmp = null;        

        //httpPost.setHeader(&quot;User-Agent&quot;, &quot;SET YOUR USER AGENT STRING HERE&quot;);
        httpPost.setHeader(&quot;Accept&quot;,
&quot;text/html,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&quot;);

        if (contentType != null) {
            httpPost.setHeader(&quot;Content-Type&quot;, contentType);
        } else {
            httpPost.setHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
        }

        try {
            tmp = new StringEntity(data,&quot;UTF-8&quot;);
        } catch (UnsupportedEncodingException e) {
            Log.e(&quot;Groshie&quot;, &quot;HttpUtils : UnsupportedEncodingException : &quot;+e);
        }

        httpPost.setEntity(tmp);

        Log.d(&quot;Groshie&quot;, webServiceUrl + &quot;?&quot; + data);

        try {
            response = httpClient.execute(httpPost,localContext);

            if (response != null) {
                ret = EntityUtils.toString(response.getEntity());
            }
        } catch (Exception e) {
            Log.e(&quot;Groshie&quot;, &quot;HttpUtils: &quot; + e);
        }

        return ret;
    }

    //Use this method to do a HttpGet/WebGet on the web service
    public String webGet(String methodName, Map&lt;String, String&gt; params) {
    	String getUrl = webServiceUrl + methodName;

    	int i = 0;
    	for (Map.Entry&lt;String, String&gt; param : params.entrySet())
    	{
    		if(i == 0){
    			getUrl += &quot;?&quot;;
    		}
    		else{
    			getUrl += &quot;&amp;&quot;;
    		}

    		try {
				getUrl += param.getKey() + &quot;=&quot; + URLEncoder.encode(param.getValue(),&quot;UTF-8&quot;);
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

    		i++;
    	}

        httpGet = new HttpGet(getUrl);
        Log.e(&quot;WebGetURL: &quot;,getUrl);

        try {
            response = httpClient.execute(httpGet);
        } catch (Exception e) {
            Log.e(&quot;Groshie:&quot;, e.getMessage());
        }

        // we assume that the response body contains the error message
        try {
            ret = EntityUtils.toString(response.getEntity());
        } catch (IOException e) {
            Log.e(&quot;Groshie:&quot;, e.getMessage());
        }

        return ret;
    }

    public static JSONObject Object(Object o){
    	try {
			return new JSONObject(new Gson().toJson(o));
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
    }

    public InputStream getHttpStream(String urlString) throws IOException {
        InputStream in = null;
        int response = -1;

        URL url = new URL(urlString);
        URLConnection conn = url.openConnection();

        if (!(conn instanceof HttpURLConnection))
            throw new IOException(&quot;Not an HTTP connection&quot;);

        try{
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod(&quot;GET&quot;);
            httpConn.connect(); 

            response = httpConn.getResponseCode();                 

            if (response == HttpURLConnection.HTTP_OK) {
                in = httpConn.getInputStream();
            }
        } catch (Exception e) {
            throw new IOException(&quot;Error connecting&quot;);
        } // end try-catch

        return in;
    }

    public void clearCookies() {
        httpClient.getCookieStore().clear();
    }

    public void abort() {
        try {
            if (httpClient != null) {
                System.out.println(&quot;Abort.&quot;);
                httpPost.abort();
            }
        } catch (Exception e) {
            System.out.println(&quot;Your App Name Here&quot; + e);
        }
    }
}
</pre>
</p>
<p>Based on the structure of your JSON file develop a class in your project to support the structure. For example for the above mentioned service I developed this class. </p>
<p>The JSON returned has this structure {&#8220;alertid&#8221;:&#8221;1&#8243;,&#8221;alerttext&#8221;:&#8221;This is test&#8221;,&#8221;alertdate&#8221;:&#8221;2010-02-11 09:03:40&#8243;}</p>
<p>
<pre class="brush: java; title: ; notranslate">
package josecgomez.com.android.dev.webservice.objects;

public class alerts {

	public int alertid;
	public String alerttext;
	public String alertdate;

	@Override
	public String toString()
	{
		return &quot;Alert ID: &quot;+alertid+ &quot; Alert Text: &quot;+alerttext+ &quot; Alert Date: &quot;+alertdate;

	}
}
</pre>
<p>Once you&#8217;ve done this in your android activity you may execute the following code to access the web service</p>
<p>
<pre class="brush: java; title: ; notranslate">
 // Instantiate the Web Service Class with he URL of the web service not that you must pass

        WebService webService = new WebService(&quot;http://www.sumasoftware.com/alerts/GetAlerts.php&quot;);

        //Pass the parameters if needed , if not then pass dummy one as follows
		Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
		params.put(&quot;var&quot;, &quot;&quot;);

		//Get JSON response from server the &quot;&quot; are where the method name would normally go if needed example
		// webService.webGet(&quot;getMoreAllerts&quot;, params);
		String response = webService.webGet(&quot;&quot;, params);

		try
		{
			//Parse Response into our object
			Type collectionType = new TypeToken&lt;List&lt;alerts&gt;&gt;(){}.getType();
			List&lt;alerts&gt; alrt = new Gson().fromJson(response, collectionType);

		}
		catch(Exception e)
		{
			Log.d(&quot;Error: &quot;, e.getMessage());
		}
</pre>
</p>
<p>Please note that the above code is for accessing collection of items, if you are attempting to access a single item there should be a slight modification to the code as follows</p>
<p>
<pre class="brush: java; title: ; notranslate">
/* Replace
Type collectionType = new TypeToken&lt;List&lt;alerts&gt;&gt;(){}.getType();
List&lt;alerts&gt; alrt = new Gson().fromJson(response, collectionType);
with
*/
alerts alert = new Gson().fromJson(response, alerts.class);
</pre>
</p>
<p>The above method uses GET if you need to INVOKE POST there should be a slight modification to the above code as follows. I hope this helps.</p>
<p>
<pre class="brush: java; title: ; notranslate">
/* Replace
String response = webService.webGet(&quot;&quot;, params);
with
*/
webService.webInvoke(&quot;&quot;, params);
</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
	</channel>
</rss>

