Privacy Is Dead, Time To Prepare For The Future

Personal privacy is over.

The world knows more about you than you do and soon it will know even more.

We can keep fighting the battle to secure our privacy or we can learn how we need to live in the coming age where all of our actions are potentially in public view.

Before you get worried that I am going all political on you, don’t worry, I’m not condoning the invasion of personal privacy or the eradication of it, but at the same time I’m not supporting it either.

I’m simply looking at the patterns that are emerging as the technology of our society increases, making this transformation inevitable.

I’m actually staunchly opposed to expressing my political thoughts publicly from any forum, even from my own blog, and I often recommend others do the same, mostly because of this transformation that is taking place.  I’ll talk more about that a little later on, but first let me tell you why privacy is indeed dead or at the very least dying.

It’s more than Google Glass

Google Glass itself may not change the concept of personal privacy, but wearable computing is certainly the future.

Google Glass helps end privacy

Google Glass

What Google Glass does do, is sets up the stage for wearable computing to go mainstream.

I hear many people complaining about Google Glass saying that they would never wear the technology in public, because they would look like a geek or a dork.

But, this is exactly what makes innovations like Glass so important.  The first thing that changes in society is perceptions.

Google Glass may not have the momentum to bash through the barrier of the “dorkiness” of wearing a computer on your head, but it will make a dent in that wall and over time that wall will come crashing down.

When everyone is wearing cameras it will be impossible to control them

We’ve already been through this before.

We’ve been through it at least two times that I can think of.

First, there was the USB drive.

Corporate privacy is easily averted

All of a sudden we could plug a small device into just about any computer and pull data off of it or put data on it.

Computers without disk drives or network access were no longer inaccessible.

The data on them was no longer securable.

Sure, many companies tried to make it so PCs in their buildings were secured, but most companies realized that they would just have to deal with this new reality.  You had to realized that if a person had access to data on a computer, they could take that data home if they wanted to.

The same type of thing happened when all cell phones started getting quality cameras on them.

Secure facilities tried to prevent people from taking pictures by disallowing employees to bring in cell phones that had cameras, but that didn’t last long.

It became apparent pretty quickly that it would be just about impossible to prevent human beings who now were part human, part iOS or Android, from bringing their cell phone into a building.  And, even if you could, someone who really wanted to take a picture would find another way.  The technology that brought tiny cameras to the backs of every cell phone also pioneered the mass creation of tiny cameras that could easily be hidden anywhere.

Already governments and family matters have been thrust into public view

We currently live in a society where it is just about impossible for public figures or government to do an action in public and try to keep it secret.

Think about all the times in the last few years when a police officer stepped over the line or a government tried to quell a public protest by using violence or excessive force.

Each and every time, not only was there photographs and videos of the incidents, but the information spread to the entire world almost instantly through mediums like Twitter and Facebook.

The fact of the matter is, it is almost impossible to hide or cover up anything that occurs in public view.

Consider the amazing and tragic events that recently occurred at the Boston Marathon.  In a huge crown of people, it only took about a day to identify two suspects out of the thousands of people in the crowd using images and video provided by the public.

This event was significant, because it showed that even when people aren’t trying to capture data about you in public, they are capturing data.

You don’t have to worry about the government tracking you. The government doesn’t have the power or capability to do it.  Instead, you are tracking yourself, you are tracking the government.

Oh, and if you still think family matters are private, you probably haven’t heard of this thing called Facebook.

Don’t think you can get a divorce, or even get into a heated argument with your teenager and not have it become public knowledge on Facebook.

The problem is that there are too many leaks now to private family matters and it is too easy for those leaks to spread the information.

Worse yet, those naked pictures you took of yourself, or unfortunately your less worldly-wise teenager took of themselves, that you thought no one would see… all I can say is “good luck with that.”

The reality is the trend against privacy will not reverse

Not only are you willingly providing your own private information, but companies are actively mining it.

From tracking cookies, to search histories, to friends graphs, advertising link clicks, foursquare check-ins, what you post on Twitter and more, everything is being recorded and tracked.

Each piece of information by itself is not very valuable, but when you combine all this information together, a very real and precise silhouette begins to emerge from that frosted glass window you are hiding behind.

And, like I said before, even if Google Glass is not successful, it will not be long before every human walking around in public and in private wearing a camera that not only you can’t control, but likely you won’t even be able to see.

Not only will we all eventually be wearing cameras, but the data from those cameras will be instantly uploaded to the cloud, where it will become a permanent record.

There are several unstoppable factors that will continue to improve over time, which will fuel this trend:

  • Miniaturization of technology
  • Increase in efficiency of batteries
  • Increase in processing power
  • Prevalence of social networks

As technology gets smaller and is able to be more mobile, and the ability to crunch big data and distribute data through social networks increases, privacy will greatly diminish.

The reality is we are transitioning from a society where private is default and public is a choice, to one where public is default and making things private requires considerable effort and in some cases is impossible.

How to live in this new “public by default” world

Rather than uselessly spending our energies trying to fight the trend of the world, it is better to spend those energies tempering our behavior to fit the world we are living in and will soon be born into.

It starts with getting in the habit of assuming everything we put on the internet will not only be made public, but will likely be a permanent record that is easily searchable.

Many times throughout the day I watch my Twitter or Facebook feed fly by and I cringe at all the people who are posting their own private opinions that should not be made public.

I’m not saying you can’t have an opinion, but I am saying that you have to be wary that the opinions you express will become visible by more than just the people you share them with and will become a permanent record which you cannot be alienated from.

Are you a republican?  Are you a democrat?  Perhaps you are a libertarian or a communist?  Do you support gun control?  Are you pro-choice?

Good!  Stand for something, but there isn’t much of a need to say it out loud.  Let your actions stand for you, they are more powerful than words anyway.

The problem with tweeting about your political views is that they may change.  You might be leaning one political direction today, but 5 years from now, you have changed your mind completely.  But, guess what won’t ever change?  That’s right, the permanent record of what you said on the internet.  If you ever decide to run for office or even go on a date, those words you said may come back to haunt you.

And even if your mind doesn’t change, do you really want to decisively set half of the world population directly against you?  I can’t image many scenarios where this is a good idea.  Even in politics, bipartisan political figures are usually much more successful.  (Ok, I made that up, but I think it’s true.)

I’m getting a little bit away from the point, but what I am trying to say is that you need to strongly consider things before you put them on the internet, because what you say online is public and permanent.

It goes beyond just the internet of course, even though it may start there.

We have to prepare ourselves for a world in which the moment we step out our door our actions are recorded.

In this kind of world, we have to be careful not to try to hide things that are likely to be destructive to us if revealed, because we know that what is hidden is likely to be revealed.

It means being more upfront and honest in our dealings and being careful to manage our image to make the focus be on the images and presentation that we desire while diminishing the focus on the image we do not desire.

When you don’t have control over the information itself, you have to instead focus on controlling how that information is presented.

It all comes down to living in such a way that clearly reflects the values you are trying to represent and knowing that perception is 100 times more important than reality.

There is no time like the present

If you are still living like you can hide your tracks and like your track record doesn’t matter, you’d better stop now, before it’s too late!

The answer isn’t to try to find better hiding places for your secrets and to try to wall yourself away from the world, but instead of accept the reality of the situation and find the best way to adapt to it.

“Man is not what he thinks he is, he is what he hides.”
― André Malraux

If you like this post don’t forget to Follow @jsonmez or subscribe to my RSS feed.

Time Traveling To The Future Of User Interfaces

I really dislike using a keyboard and a mouse to interact with a computer.

keyboard

Using a mouse is a more universal skill—once you learn to use a mouse, you can use any mouse.  But, keyboards are often very different and it can be frustrating to try and use a different keyboard.

When I switch between my laptop and my desktop keyboard, it is a jarring experience.  I feel like I am learning to type all over again.  (Of course I never really learned to type, but that is besides the point—My three finger typing style seems to work for me.)

laptop

When I switch to a laptop, I also have to contend with using a touchpad instead of a mouse, most of the time.  Sure, you can plug in a mouse, but it isn’t very convenient and you can’t do that everywhere.

I also find that no matter how awesome I get at keyboard shortcuts, I still have to pick up that mouse or use the touchpad.  Switching between the two interfaces makes it seem like computers were designed for 3 armed beings, not humans.

Even when I look at a laptop, it is clear that half of the entire design is dedicated to the keyboard and touchpad—that is a large amount of wasted space.

I’m not going to say touch is the answer

You may think I am going in the direction of suggesting that tablets solve all our problems by giving us a touch interface, but that is not correct.

Touch is pretty awesome.  I use my iPad much more than I ever thought I would.  Not having the burden of the keyboard and mouse or touchpad is great.

But, when I go to do some text entry on my tablet or my phone, things break down quite a bit.

On-screen keyboards are pretty decent, but they end up taking up half of the screen and the lack of tactile feedback makes it difficult to type without looking directly at the keyboard itself.  Some people are able to rely on autocorrect and just let their fingers fly, but somehow that seems dirty and wrong to me, as if I am training bad habits into my fingers.

touch

Touch itself is not a great interface for interacting with computers.  Computer visual surfaces are flat and lack texture, so there is no advantage to using our touch sensation on them.  We also have big fingers compared to screen resolution technology, so precision is also thrown out the window when we relegate ourselves to touch interfaces.

It is completely silly that touch technology actually blocks us from viewing the part of the screen we want to touch.  If we had greaseless pointy transparent digits, perhaps touch would make the most sense.

Why did everything move to touch then?  What is the big thing that touch does for us?

It is pretty simple, the only real value of touch is to eliminate the use of a mouse or touch pad and a keyboard.

Not convinced?

I wasn’t either, till I thought about it a bit more.

But, consider this… If you were given the option of either having a touch interface for your tablet, or keeping the mouse-like interface, but you could control the mouse cursor with your mind, which would you prefer?

And that is exactly why touch is not the future, it is a solution to a specific problem, the mouse.

The real future

The good news is there are many entrepreneurs and inventors that agree with me and they are currently building new and better ways for us to interact with computers.

Eye control

This technology has some great potential.  As the camera technology in hardware devices improve along with their processing power, the possibility of tracking eye movement to essentially replace a mouse is becoming more and more real.

There are two companies that I know are pioneering this technology and they have some pretty impressive demos.

TheEyeTribe as an “EyeDock” that allows for controlling a tablet with just your eyes.

2013-03-03_13-31-09

They have a pretty impressive Windows 8 tablet demo which shows some precise cursor control using just your eyes.

Tobii is another company that is developing some pretty cool eye tracking technology.  They seem to be more focused on the disability market right now, but you can actually buy one of their devices on Amazon.

The video demo for PCEye freaks me the hell out though.  I don’t recommend watching it before bed.

But Tobii also has a consumer device that appears to be coming out pretty soon, the Tobii REX.

Tobii_rex_LE_Picture_montage_backfront619x220

Subvocal recognition (SVR)

This technology is based on detecting the internal speech that you are generating in your mind right now as you are reading these words.

The basic idea is that when you subvocalize, you actually send electrical signals that can be picked up and interpreted.  Using speech recognition, this would allow a person to control a computer just by thinking the words.  This would be a great way to do text entry to replace a keyboard, on screen or off, when this technology improves.

NASA has been working on technology related to this idea.

And a company called ambient has a product called Audeo that is already in production.  (The demo is a bit rough though.) You can actually buy the basic kit for $2000.

technology-promo

Gesture control

You’ve probably already heard of the Kinect, unless you are living under a rock.  And while that technology is pretty amazing, it isn’t exactly the best tool for controlling a PC.

But, there are several other new technologies based off gesture control that seem promising.

There are two basic ways of doing gesture control.  One is using cameras to figure out exactly where a person is and track their movements.  The other is to use accelerometers to detect when a user is moving a device, (an example would be the Wii remote for Nintendo’s Wii.)

2013-03-03_13-34-37A company called Leap, is very close to releasing a consumer targeted product called Leap Motion that they are pricing at only $79.  They already have plans to sell this in Best Buy stores and it looks very promising.

Another awesome technology that I already pre-ordered, because I always wanted an excuse to wear bracers, is the MYO, a gesture controlled armband that works by a combination of accelerometers and sensing electrical impulses in your arm.

two_rings

What is cool about the MYO is that you don’t have to be right in front of the PC and it can detect gestures like a finger snap.  Plus, like I said, it is a pretty sweet looking arm band—Conan meets Bladerunner!

Obviously video based gesture controls won’t work well for mobile devices, but wearable devices like the MYO that use accelerometers and electrical impulse could be used anywhere.  You could control your phone, while it is in your pocket.

Augmented reality and heads up displays

One burden of modern computing that I haven’t mentioned so far is the need to carry around a physical display.

A user interface is a two-way street, the computer communicates to the user and the user communicates to the computer.

2013-03-03_13-36-29Steve Mann developed a technology called EyeTap all the way back in 1981.  The EyeTap was basically a wearable computer that projected a computer generated image on top of what you were viewing onto your eye.

Lately, Google Glass has been getting all the attention in this area, as Google is pretty close to releasing their augmented reality eyewear that will let a user record video, see augmented reality, and access the internet, using voice commands.

Another company, you may not have heard of is Vuzix, and they have a product that is pretty close to release as well, Smart Glasses M100.

Brain-computer Interface (BCI)

Why not skip everything else and go directly to the brain?header_set

There are a few companies that are putting together technology to do just that.

I actually bought a device called the MindWave from NeuroSky, and while it is pretty impressive, it is still more of a toy than a serious way to control a computer.  It basically is able to detect different brain wave patterns.  It can detect concentration or relaxation.  You can imagine, this doesn’t give you a huge amount of control, but it is still pretty fascinating.

I haven’t tried the EPOC neuroheadset yet, but it has even more promise.  It has 14 sensors, which is a bit more intrusive, but it supposedly can detect your thoughts regarding 12 different movement directions, emotions, facial expressions, and head rotation.

So where are we headed?

It is hard to say exactly what technology will win out in the end.

I think we are likely to see aspects of all these technologies eventually combined, to the point where they are so ubiquitous with computer interaction that we forget they even exist.

I can easily imagine a future where we don’t need screens, because we have glasses or implants that directly project images on our retinas or directly interface with the imaging system in our brains.

I easily see us controlling computers by speech, thought, eye movement and gesture seamlessly as we transition from different devices and environments.

There is no reason why eye tracking technology couldn’t detect where our focus is and we could interact with the object of our focus by thinking, saying a command or making a gesture.

What I am sure of though is that the tablet and phone technology of today and the use of touch interfaces is not the future.  It is a great transition step to get us away from the millstone around our necks that is the keyboard and mouse, but it is far from the optimal solution.  Exciting times are ahead indeed.

If you like this post don’t forget to Follow @jsonmez or subscribe to my RSS feed.

Why My Kid is an iKid

Sophia got her first introduction to the iPad at about 3 months old.

As soon as she could sit in a rocker chair my wife and I let her start playing on the iPad. 

002

We started off with just one game, Interactive Alphabet by Piikea.  It is basically a game that goes through the Alphabet and lets the baby interact with some of the pictures.

We added a few more ABC type of games as she got a bit older, but we mainly just let her play with that one game, because we figured it would be great to let her start seeing letters and learning the alphabet as early as possible.

Right from the get-go she would swat at the screen.  She didn’t immediately understand the cause and effect, but she quickly grasped the idea that when she hit the screen, something would happen.

After a while she became pretty good at being able to do the simple things in the ABC game.  She would still swat the screen, but purposefully swat certain areas in order to do something like build a sandcastle.

Around 12 months, we started adding a bunch more apps.  We added some interactive books and a couple of simple games.

IMG_4492

Sophia was learning how to do many more things in the apps.  She could point with a couple of fingers and very purposefully touch certain areas of the screen. 

She really didn’t have any concept of touching and dragging though, and would often run into problems of having one hand leaning on the iPad which was causing the other hand’s touches not to register.

She’s now 18 months and she is an iPad master.

IMG_6639

Sophia can now:

  • Turn on the iPad
  • Unlock the iPad
  • Pick which app she wants to play out of her folders
  • Use the home button to exit an app
  • Double press the home button to switch to a recent app
  • Navigate through menus in apps and get back to the app
  • Use the table of contents in books to pick the page she wants

She also asks for the iPad by name.  She has about 40 apps on the iPad that she subsumed from my wife.  It seems like she is learning something new every day now.

The world is changing

Our children, especially the youngest ones, are growing up in an entirely different world than has existed ever before.

Binary world

I know this has been said many times before and it could be argued that my generation also grew up in an entirely different world than my parents, but I think the change we are seeing now is much more substantial.

I predict that this generation will be known as the tablet generation.  With Windows 8 now released we are going to see a rapid decline of non-touch devices.  In a few years all laptops will be touch screen retina displays.

There are some fundamental changes going on in how we interact with computers and even what defines a computer.

Yes, I know you’ve heard all this before, but why is this important?

It is important because the real shift I see is the shift between a primarily analog focused world view to a primarily digital focused world view.

For me the iPad or the computer is an attempt to replicate some process or experience in the real world.  No matter how long I work with computers or use these devices, I cannot escape my world view.  Analog always comes first.

For our children things are different.

I can’t say for sure that picking up a pencil and being able to write is a skill that will even be necessary.

It is very likely that this coming generation will view things through the digital lens first and the analog world will be secondary.

I don’t mean they’ll be jacked into computer all day and live in a virtual world, but I do think that while we try to relate software to tangible things the coming generation is likely to view software as the primary and tangible objects as secondary.

Think about music.  Ever had an 8Track?  How about a cassette tape? CD anyone?

How do we think of music today?  One word comes to mind—MP3.

What started out as a physical record eventually lost its purpose and is now so heavily digital that we tend to think in terms of the digital and don’t even consider the tangible anymore.

The same thing is currently happening with books, movies and to some degree money.

Why we let Sophia be an iKid

With the changing world, computer literacy is more important than ever before.

Even in the world we live in now, it is just about impossible to get any kind of non-labor intensive job without being able to use a computer.

If computer literacy is arguably going to be the most important skill for anyone to have in the future, why not start as young as they start to show an interest?

I think it is a huge asset to develop in our children the ability to use a computer as easily and mindlessly as the ability to eat with a fork and a spoon.

I wish I had that ability. I could be so much more efficient if I would stop writing down lists on pieces of paper and instead pull up my iPad or other tablet to jot down ideas and completely replace paper in my life.

And sure I could learn to wean myself off of the analog world, but I want my daughter to be able to think first in the digital world.  She’ll be way more efficient and see things from a better perspective than I ever will.

Aside from that, my wife and I find that the iPad is an excellent learning tool to help Sophia learn to learn.

There are so many things she is able to teach herself using that iPad.

She already:

  • Has a vocabulary of over 100 words
  • Can count to 4 in order and count actual objects
  • Can say most of her ABCs
  • Can recognize most letters
  • Can name many animals and objects

abc

Much of what she knows she learned at her own pace based on what she was interested in playing on the iPad.

For example, one week she’ll be playing many of the numbers apps.  For a whole month she just wanted to do alphabets.

The iPad gives her the freedom to be able to choose what she wants to learn and to do it effortlessly.  She is developing the skills to be able to self-educate.  Sure, we still read books to her and try to teach her, but she seems to get a large amount of her knowledge from what she learns playing on the iPad.  (At least the reinforcement of what she has learned.)

Overall I don’t think there is any reason to stop her from playing on the iPad.  I know some people equate it to TV, but I think it is fundamentally different.  The apps she plays on the iPad are interactive.  You can’t mindlessly sit and watch the iPad.  Instead, there is a constant feedback loop that is not present with TV.

Also we can carefully monitor the apps she uses.  The TV is an open system that brings unknown content into your house, where the iPad can be used as more of a closed system.

To summarize, I think we are preparing her for the future and giving her a huge head start in life.

How to get started

So you may be wondering how to best go about getting your baby or toddler started with the iPad.

While I’m not a child development expert, I can give you some advice from what my wife and I have learned in this process.

I’d start by picking up a used first generation iPad and a good case.

You can of course get a newer iPad or even another tablet, or the iPad mini, but just be aware of two things.

  1. Babies don’t have very precise coordination with their hands so small screen are going to be hard for them to use.
  2. Babies tend to throw things, especially when they get frustrated.

The next thing you need is apps.  My wife, Heather, wrote up this section for me.  So, if you notice the grammar is perfect and is written with a much higher skill level than my usual writing, that is why.

(Please let me know if you have some other ones appropriate for the ages.  I’d like to make a nice resource for other iKid believers.)

3 Months – 12 Months

  • Interactive Alphabet by Piikea.  This is by far the best app I’ve seen for the youngest of kids. It has a baby mode which prevents babies from exiting by accidentally batting a menu button and most of the items respond to simple taps or swipes.
  • Juno’s Musical ABCs by Juno Baby.  This app also goes through the alphabet but with a musical theme. The interactions aren’t as neat as the Piikea app and the button to return to the menu is prominent and easily pressed.
  • Peekaboo Baby. This is my app.  Warning, it is very simple.  I was learning MonoTouch and wrote it in a day as an experiment.

12 Months to 18 Months

  • Seuss ABC, Green Eggs These stories have autoplay, read to me, or self-reading features and will say the word of anything the child touches on the screen. There is actually an entire line of the Dr. Seuss books, but I prefer these two. The ABC app is great because each letter is said multiple times. The Green Eggs app is my daughter’s favorite, and I suspect this is because so many of the words in this story (eggs, boat, house, mouse, car, train, etc.) are ones most 18 month olds know. These books are a little long so if you’re more interested in the stories, go with the Bright and Early Board Books instead of these apps. The Mercer Mayer, Little Critter books are also available and tend to be shorter in length.
  • I Hear Ewe This neat little app has three screens of picture tiles: two of animals, one of vehicles. When touched it says: "this is the sound a [insert animal or vehicle here] makes:" I like this because it doesn’t require page navigation. A child can sit and do this for a short period and when they get bored, you can switch the screen for them. Sophia plays this occasionally at 18 months but it doesn’t hold her interest as much, so I suggest trying it at a little younger age.
  • Pat the Bunny by Random House. There is both a paint and interactive option with this app. The paint seems to always crash, most likely due to the mad tapping of a toddler, so I avoid it. The read option has a bunch of items on the screen that kids can interact with (turn off a light, put shave gel on daddy’s face, wave bye bye, play peek a boo, etc.) I’ve never seen the real book, but I wouldn’t be surprised if this app is better than the book. Changing screens is manual and may require adult help. There is an obnoxious Easter egg on every page that brings up the bunny.
  • Princess Baby by Random House. I was actually disappointed there wasn’t more to this app, but Sophia has played it enough that it makes the list. It begins by having you “Choose your favorite princess.” Each princess has 3 toys that can be interacted with in a very limited way: wand, drum, ball, flower, blocks, cat. The princess can be put to bed, which Sophia likes doing over and over and over again.

18 Months +

  • A Monster at the end of this book.  Starring your lovable, furry pal Grover from Sesame Street, this app has a very cute storyline. In order to advance through the book certain tasks, such as touching knots to untie the page or knocking down bricks must be performed. This is another one where the app may be better than the book itself. One bonus: the pages are locked when Grover is talking, which keeps an eager toddler from advancing through too quickly. My daughter loved this book earlier on but I had to help her with some of the action pages and it was just recently that she started doing it all on her own.
  • Another Monster at the end of this book.  Starring Grover and Elmo, some of the tasks are a little trickier than the first book (matching colors, wiping away glue), but did I mention it has Elmo?
  • Little Fox by GoodBeans. This is one of my favorite apps. It has 3 different songs to choose from and each has its own scene: London Bridge is Falling Down, Old MacDonald, and The Evening Song. Each scene is cleverly interactive and entertaining. Old Mac Donald has 4 seasons to select from and the interactions change based on the season. There is also a little "fox studio" with a ton of interactive objects used to make music.
  • Nighty Night by GoodBeans.  Adorable. The animals at the farm house need to go to sleep. This is done by clicking on the area each animal resides in and turning off the light. The animals respond to touch. Additional animals can be purchased (2 sets of 3 animals each).
  • Itsy Bitsy Spider by Duck Duck Moose.  Another fantastic app, this may be the one Sophia has clocked the most time with. In order to progress through this app, you must click on the spider. Each time the spider is touched one line of the song is sung and the spider moves. There is a lot to interact with at each spot and one the second time through the song there are decorated eggs the child can collect on the spider’s back. There is a cute little narrator fly that teaches the child about items the child clicks on (i.e clouds, the sun, rainbows).
  • Ewe Can Count.  This is a cute counting game where you count a random number of sheep, horses, apples, etc. There is a learning and a quiz mode.
  • Logic Lite.  This app is great because it teaches the complicated click and drag gesture. The full version has three additional tile sets: Numbers – match dots to the written number, Pictures – match a picture that contains a shape to the shape it contains, and Letters. The letters are great at 18 months, but the other two are too complex.

Your mileage may vary

Having your little one use an iPad might not work out as well as it has for us, so I think it is only fair to disclose some of the circumstances which govern our life that may help to make our experience successful.

  1. My wife is a stay at home mom.  She used to be a techie, but left the digital world to raise our daughter.  I only bring this up, because she interacts with Sophia all day.  If we were putting Sophia in day care, I would be more hesitant to give her the iPad during our interactive time with her.  (But I would probably try to get the day care to let her use it.)
  2. We have almost 0 TV in our house.  I don’t watch any TV at all or movies.  My wife very rarely watches TV and Sophia never does.  I think this is important, because if she were watching TV, I would also be a bit more hesitant to let her play with the iPad as much.
  3. We do LOTS of other activities.  Just about every day of the week she has either swimming, gym class, play date, or something else going on.  My point here is that she gets plenty of outside time, social interaction and physical activity.
  4. Sophia took the to the iPad right away.  We didn’t have to force it on her or even encourage her to use it.  I don’t know if other kids are like this or not, although I suspect most would be.

So doing the same thing my wife and I are doing might not be the best for you family—you’ll have to decide for yourself—but as far as our daughter has been concerned the experience has been overall positive and beneficial.

Introduction to MonoGame

I’ve been playing around quite a bit with MonoGame lately and thought I would take some time to write a bit about it and talk about how to get started.

I’m also currently working on a Pluralsight course on cross platform development with MonoGame.

MonogameLogo100x100

What is MonoGame?

Well, if you are familiar with XNA, then you already know what MonoGame is.

If you are not familiar with XNA though, it is basically a game development framework that allows for creating games quickly without having to write all that repetitious code that all games need.

Basically it makes creating games more about the game and less about the technical details.

The only problem with XNA is that it only really works for Windows, XBox360 and Windows Phone 7.  If you want to create a game on Android and iOS, you can’t use XNA.

This is where MonoGame comes in.  MonoGame is an open source port of the XNA framework that can run on many more platforms that Microsoft’s XNA.

Great, so what does this actually mean?

Well, if you are interested in game development, especially if you are interested in game development for the most popular platforms today, MonoGame might be able to help you to write pretty close to the same exact code and have it work on Android, iOS, Windows 7, Windows 8, Windows Phone 7, MacOS, XBox 360, Linux and the new Playstation console.

That is pretty awesome!  Especially if you are trying to monetize your effort.

In my mind MonoGame helps overcome two huge barriers to getting into game development.

  1. Difficulty of monetizing the effort.  By allowing the same code to be shared on most platforms, a game developer can get paid for their effort in multiple marketplaces.
  2. Not knowing where to get started.  The XNA API is so simple to use that you can get a simple game, like a Pong clone for example, up and running in about a couple of hours.

Also, because MonoGame is basically just XNA, you can find a whole host of resources on how to develop a game using the platform.

In my upcoming Pluralsight course, I show how to create a Pong clone on Windows and then we get that game up and running on Android, iOS and Windows Phone 7, with minimal changes.

dgun-853-50-games-pr-h

Getting started

It can be a bit challenging to find good information to get started in each platform using MonoGame, but the basics are located on the Github page.

For the Windows tutorial there, you can use Visual Studio instead and use the MonoGame installer.

For each platform things area slightly different, but really not all that hard.  If you want to have your game run in Android and iOS, you’ll need Mono for Android and MonoTouch respectively.

For Android development, you can use Visual Studio as long as you have Mono for Android installed and all you really need to do is link your files from your Windows project and create a small bit of startup code in an Android Activity to start the game.

For iOS development, you will need to use MonoDevelop, which is packaged with the install of MonoTouch.  MonoTouch itself uses XCode and the iPhone SDK, so you have a bit more installing to do there, but the idea is pretty much the same.  One you have MonoTouch running on your Mac, you can link over the files from your Windows project, add a small bit of startup code, and you are up and running.  (You’ll also need to download the actual MonoGame source code to add to your project, since there isn’t an installer for Mac currently.)

Xamarin also has a seminar they did on MonoGame to help you get started.

True cross platform development, finally

At least for game developers.  For other applications in the mobile space, there are some solutions that help you share your code, but nothing that really allows you to have near 100% portability without a big sacrifice.

I was pretty amazed the first time my game just ran on my Android and iOS devices with virtually no changes.

I’d definitely encourage you to check out MonoGame and stay tuned for my Pluralsight video on the topic, where I will go through all the details of creating a game and getting it running on most of the major platforms.

Predicting the Mobile Future

Many people have been asking me about my predictions for the future as far as the mobile platforms go.

I thought I would take a moment to write up a blog post detailing out what I think we will see in the next couple of years for mobile phones and tablets.

gn-psychic

Windows 8 changes everything

Or at least it has the potential to.

There are quite a few game changers built into Windows 8 that have a huge potential to influence and disrupt the market.

One OS for mobile and desktop

The idea that Windows 8 will essentially run on mobile and desktop is going to force the hand of other platforms.

I really like my iPad, but it could never be a total PC replacement.

Now imagine what happens if I can have an iPad, but it can snap right into a keyboard to make it into a laptop and it is running an OS that can do everything I need.

Suddenly I have to question why I need a separate iPad.

PC manufacturers have been chomping at the bit to break into the tablet market for some time now.  It was a slap in the face for Apple to produce the first generally accepted “good” tablet after so many PC manufacturers had tried and failed for years earlier.

We can learn a lot from a tablet

What makes the iPad so good?

In my opinion, 4 things:

  1. Extremely portable and lightweight
  2. Good touchscreen input, so I don’t need a physical keyboard most of the time
  3. App store!
  4. Instant on

There isn’t even a need for a Windows 8 tablet.  Instead, I predict we are going to see Windows 8 Ultrabooks with removable keyboards.

As long as this new class of computers can hit the 4 items I like about the iPad, it could really cause some disruption in that market.

What about the cloud?

cloud_0

I see some big things changing and evolving on this front as well.

Apple introduced iCloud and my first real experience with it as a consumer was playing a game on my iPad, then switching to my iPhone and having the game restore me to the exact point I was on the iPad.

This will become the standard.

Regardless of how devices transform, I don’t see us getting away from having some kind of a phone.  We might merge tablet and laptop, but we are going to always have at least two devices.

It is going to be expected that data from one device is available on the other device.  Many applications already support this, but I predict that we will see this get more tightly integrated into the operating system.

Microsoft, Google and Apple are all heavily invested in this area with a few different twists, but I see all the paths eventually merging to cloud based OSes with full app virtualization that streams bits to be executed to the clients and has the clients cache the app code.

What does this mean?

It means your user experience changes so that you log into your phone or tablet and when you do, you see the same thing regardless of device.  You don’t even know you have two different devices, except for the form factor.

It also means that you don’t have the same concept of apps for your phone or tablet anymore.  Instead you purchase an app and it is streamed to you when you want to use it.  So as a user, you don’t need to worry about downloading the application or managing updates.

Think of it as the web, but instead of HTML you have binary executable code.  Spoon already does this.

How about development?

If you are reading this blog, you are probably more interested in what is going to happen in terms of developing applications for these platforms.

I have some predictions here as well.

Right now it is very difficult to develop an application that will run on multiple platforms.  Trying to target Android, iOS and Windows Phone is a bit of a challenge.

Even with great tools like MonoTouch and Mono for Android or PhoneGap, it is no easy task.

There is a big push to make everything web apps.  Some people believe HTML 5 will be the future, but I am not quite so sure.

I do think that the most successful platform, in the long run, will be the one easiest to develop for.  History tells me this is true.  (Why is Windows so successful?)

Microsoft again has a chance to change the future with Windows 8’s WinRT.  Suddenly web developers can write Javascript to program windows.  Not only that, but they can reuse much of that code to create a web application.

Think about where Windows 8 will run.  Desktop, laptop, tablet, phone.  Suddenly, you can create an application that can run on all of these devices, with pretty much the same code.

So what does this mean for iOS and Google?

I predict that this year Apple will announce a new programming model for iOS which will be based on Javascript.

I wouldn’t be surprised if Google did the same thing for Android.

It really makes sense on the iOS side though.  Apple is going to have to merge iOS with OSX to compete with Windows 8.  In addition, they need a better programming model.

Writing iOS apps in Objective-C is horrible!

Apple is going to have to do something to prevent web developers from flocking to Windows 8.

In the near future, I think we will be able to write applications with the code of the logic in Javascript or another language of choice, which binds against Javascript APIs for each platform.

Summarizing my predictions

So in short, here is what I think will happen within 2-3 years.

  1. Tablets and laptops merge as Window 8 targets both and iOS merges with OSX.
  2. Cloud based operating systems replace standard OSes and virtualize apps by streaming them to users.
  3. All surviving platforms natively support a Javascript based API.
  4. Decrease in need for web apps, since streaming binary apps replace that niche.

I could be wrong, I’ve been wrong many times before, but those are my predictions as of now.

MonoTouch

I’ve been so busy lately that I have neglected to write about a great platform for developing iOS applications called “MonoTouch.”

I recently released a new course on MonoTouch at Pluralsight.

I wanted to take a bit of time here to talk about MonoTouch and to tell you why you should be using it instead of developing iOS applications in Objective-C

text-monotouch

Flipping directions

GoPhoto_0197_Scanned-Image-00363

When I first started developing with iOS, I firmly believed that the job should be done using the tools that Apple provided.

I still think it is a very good idea to learn Objective-C and how to develop an iOS application using Objective-C and XCode.

But I am convinced now that overall MonoTouch is the way to go.

Objective-C is a decent language, but it has a fairly steep learning curve for a C# or Java developer.  XCode, the IDE for developing iOS applications, is a decent IDE, but it is not nearly as powerful as MonoDevelop or Visual Studio.

The reality of the situation is that Apple’s development platform is still back in 1990.  Even though there have been some changes and growth, I firmly believe now that Objective-C and the underlying technology cannot ever catch up to .NET or Java.

I don’t say this lightly.  As I said, before I developed a fairly large application in Objective-C.  I authored a Pluralsight course on iOS development with Objective-C.  I was pretty convinced this was the way to go until I gave MonoTouch a try.

An unfair test

I really gave MonoTouch an unfair test, but it passed anyway.  I set out to learn, configure, build a MonoTouch application, and deploy it to the Apple App Store in 1 weekend.

I figured if MonoTouch could pass this test then I would immediately save more than the $400 cost for the software since the next application I was going to build was going to probably take at least a week worth of time to build in Objective-C.

MonoTouch easily passed my test and really exceeded my expectations.

The main advantage

By and far the main advantage in using MonoTouch is the language.

C#’s ability to wire up events through event handlers and delegates makes working with iOS so much easier.

There are many situations in iOS where you have to create a special class to act as a delegate for providing behavior for various iOS controls and classes.  In C#, many of these delegate classes can be replaced by a C# delegate or lambda expression.

Another really painful situation in Objective-C is memory management.  If you aren’t used to tracking memory usage it takes a bit to get adjusted to it in Objective-C.  Sure, it really isn’t that hard, but once I started working with C# to build my iOS application, I realized how much faster I could fly through the code without having to even think about it.  (The newer version of Objective-C has somewhat built in memory management, but it is not a true garbage collection implementation.)

Along with C#, you get the full power of the .NET framework.  Almost all of the base class libraries from .NET are available in MonoTouch.  (You basically have the silverlight .NET profile.)

This really comes in handy in 3 main areas:

  • Working with XML
  • Working with databases
  • Calling web services

If you try to do these things in Objective-C, it is possible, but it will hurt like hell.

Give it a shot

If you are interested in developing iOS applications and you haven’t tried MonoTouch, go give it a try.  Trust me, it is worth the effort.  One of the big factors that had me developing Android applications and shying away from iOS was the hurdle of trying to learn and work with Objective-C.

MonoTouch lets you reuse your C# skills without any extra overhead, since the application is compiled down to native ARM assembly code.

If you don’t know where to get started or want to learn a little bit more about MonoTouch, feel free to check out my course on Pluralsight.

Kudos to the Xamarin team for building such a great product!

(BTW, that photo is me flipping.  Actually it is a thing I used to call “throwing myself at the ground for dramatic effect.”)

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter here.

PaceMaker for iPhone Released

Earlier this year I announced the release of an app I had been working on for Android called PaceMaker.

Finally, I have succeeded in porting the application over to iPhone and it was definitely much harder than I had anticipated.

But I am glad to announce that as of today you can find PaceMaker for iPhone in the Apple App Store.

If you don’t know what PaceMaker is, you can read about it in my original post above or in the description in the app store, but to sum it up briefly, it helps you run at a desired pace by telling you to speed up or slow down when you are running too fast or too slow.

Default@2x

A unique perspective

Having originally written the application and then porting it over to iPhone gives me a kind of unique perspective on mobile development platforms.

Although it was a bit painful at times to basically recreate the same thing I already spent so much time and energy creating, I was able to very realistically contrast the two development platforms in many areas.

One of the major pain points I experienced was in documentation.  Google’s documentation on the Android platform is sometimes lacking, but is much more complete and descriptive than Apple’s iOS documentation.

I am still quite a bit torn on which platform I like more and which platform I think will win out in the end.  I do believe that if Apple improved their developer tools and moved to a new, more modern development language, that they would have a distinct advantage.

It seems to me though that whoever integrates the best across multiple devices and gets the highest quality applications built for their platform will be the winner.  iCloud could be a huge step in that direction for Apple.

Sharing the knowledge

I’ve just talked with my curriculum director at Pluralsight and I will be doing a beginning iPhone development for .NET developers course just like the Android Development for .NET Developers course I did earlier this year.

I’m pretty excited to do this because I am going to try and draw some major parallels between the two platforms and also from the .NET perspective.

I hope to create the course just like the Android one, where we will step by step create an application from scratch and then publish it to the Apple App Store.

Look for that in the next few months on Pluralsight.net.

Dailymile.com integration

Also included with this release for iPhone and Android is Dailymile.com integration.  I think this feature is pretty cool!  So I am really excited about it!

Dailymile.com is basically a social site for runners and cyclists.  It is basically a Facebook for runners.

I have added a feature to the Android and iPhone versions of PaceMaker to allow you to post your run details, including the GPX map of your run, up to the Dailymile.com server on your wall.

So when you go for a run you can capture all the information from your run and see it on Dailymile.com.

This was quite a pain to implement as I had to implement OAuth2 authentication in both platforms and integrate with a REST API.  But what a great learning experience!

Anyway, if you are a runner out there and you get PaceMaker, feel free to send me an email or drop me a comment.  I am always looking for feedback so I can improve the app.

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter here.

OAuth and REST in Android: Part 2

In my last post we went over OAuth in general and we looked at how to use a Java library called Leeloo to authenticate with a service providing an OAuth 2 implementation.

Now that we are able to authenticate a service with OAuth, we need to be able to actually use that service to do something useful.

Many popular web service APIs like Facebook and Twitter provide a REST based implementation.

In this post I’ll show you how to easily connect to one of these web services from Android and parse any responses you get back.

AndroidREst

Should I use a REST library?

This is a valid question we should address before getting into the details.

My answer to this question is basically “no.”

I first tried the approach of using a REST library to make it easier to communicate to a REST based web service, but quickly found the overhead of the library was more than the benefit it provided.

If you come from a background of calling XML and SOAP based web services, you might be surprised by this answer.  With SOAP based web services it was a huge benefit to use a library to generate a proxy for you to call the web service and let you not have to worry about parsing XML and SOAP headers.

With REST it is completely different.  The whole point of moving to REST based web services is to simplify the process of calling web services.

Most REST based web service interfaces are extremely simple to use.  The idea is that the URL itself contains as much of the data as possible and additional data is included in the POST body.

By adding the complexity of learning a REST library and implementing the proper interfaces required to make it work seamlessly, we can easily add more complexity and overhead than just creating a HTTP request ourselves and parsing the responses.

For this approach I am going to show you how to do just that.

Calling the REST service

In order to call a REST service in Android we are going to first have to discover and understand the REST API provided to us, then make the appropriate calls with the OAuth token we got from authenticating.  Finally, we will parse the result of the call and get back our response.

Discovering the API

Because REST is not really a standard, but rather an ideal, there is not a standard way REST APIs are implemented.

You’ll have to take a look at the documentation for the REST API you want to call to figure out exactly what a call should look like.

In general though a REST API will involve making some kind of HTTP GET, POST, PUT or DELETE request and passing data through the URL or in the request body.

Here is an example of the Dailymile.com API which I have been recently integrating my app to use.

You can see the full API documentation here.

For this API, I am going to show you how I am creating a workout entry using a post.

Making the REST call

In order to make a REST call in Android, we are going to use a HttpClient object and the appropriate http request class.

In this example we are going to use the JSONObject class to create some data in JSON format that we can pass to the REST call by embedding it in the post.

I looked at the API for posting a workout entry to Dailymile, and the format of the request should look like this:

https://api.dailymile.com/entries.json?oauth_token=<token>

The API also indicates that it expects the post body to contain some JSON and gives us a list of required and optional entries that need to be in that JSON object.

Let’s take a look at how I am making this call and then we’ll break it down some.

HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(
	&quot;https://api.dailymile.com/entries.json?oauth_token=&quot; 
    + token);

httpPost.setHeader(&quot;content-type&quot;, &quot;application/json&quot;);
JSONObject data = new JSONObject();

data.put(&quot;message&quot;, dailyMilePost.getMessage());
JSONObject workoutData = new JSONObject();
data.put(&quot;workout&quot;, workoutData);
workoutData.put(&quot;activity_type&quot;, dailyMilePost.getActivityType());
workoutData.put(&quot;completed_at&quot;, dailyMilePost.getCompletedAt());
JSONObject distanceData = new JSONObject();
workoutData.put(&quot;distance&quot;, distanceData);
distanceData.put(&quot;value&quot;, dailyMilePost.getDistanceValue());
distanceData.put(&quot;units&quot;, dailyMilePost.getDistanceUnits());
workoutData.put(&quot;duration&quot;, dailyMilePost.getDurationInSeconds());
workoutData.put(&quot;title&quot;, dailyMilePost.getTitle());
workoutData.put(&quot;felt&quot;, dailyMilePost.getFelt());

StringEntity entity = new StringEntity(data.toString());
httpPost.setEntity(entity);

HttpResponse response = httpClient.execute(httpPost);

 

You can see that I am first creating an HttpClient object and an HttpPost object.  The HttpPost has its URL set to the URL for the API call and I am adding a query string parameter to provide the OAuth token we got when when authenticated in my previous post.

I set the content type to be JSON so that we can get back a JSON object from the API call and so it knows that we are passing JSON data.

Then I construct a JSON object in the format specified by the API.  The way to construct the JSON object is to basically create a set of keys and values that are specified by the API you are calling.  In this instance I have a “message” key which I put the message data into. 

The only tricky part is that JSON objects can be nested.  So if you look at the key “workout” in the example above, I am creating a brand new JSON object to use as the value for that key which has its own subkeys which could contain more JSON objects.

Doing it this way is much more simple than trying to construct the string yourself.  The string we end up constructing will look something like this:

{"message":"fun!","workout":{"distance":{"value":5,"units":"miles"},
"activity_type":"running"}}
 
Finally, I put the JSON data into a StringEntity class and set it as the entity on the HTTP Post.  Then we can call execute on the HttpClient to execute the HTTP POST.
 
Handling the response
Now that we have actually made the call to the REST service method we can handle the response by creating another JSONObject from the HttpResponse that is returned.
 
Let’s look at that code and then we can go over what is happening.
 
HttpResponse response = httpClient.execute(httpPost);
String responseString = EntityUtils.toString(response.getEntity());
JSONObject responseJSON = new JSONObject(responseString);
int workoutId = responseJSON.getInt(&quot;id&quot;);

All we are doing in this case is getting the response from the execute call on the HttpClient object, then using EntityUtils.toString to convert the response’s entity to a string representation.  Finally, we construct a new JSONObject from that string.

We can then easily extract any data out of the JSON object by using the methods on that JSON object that let us get typed values out of it.  For this example, I know that I am getting back some JSON that has a key “id” which is the id of the workout I created with my POST.

It is really that simple

The example I am showing you here is one of the more complex examples of calling a REST based API, because we are having to POST and parse JSON data.

In many API calls, you can just use an HTTP GET or a POST without any data to accomplish what you need to in the API.

Some REST based APIs will allow or require data to be passed in a different format, but most of them use JSON notation, which I find the easiest to work with.

Hopefully with these series of posts you can now authenticate against an OAuth 2 based service and make calls to the API to get and manipulate data in Android.

If you have any questions, feel free to drop me a line or post in the comments below.

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter here.

OAuth and REST in Android: Part 1

I recently had the fun experience of learning a bit about both OAuth and making REST web service calls in Android and since I didn’t find much good material out there, I thought I would share it here.

OAuthPicture

Let’s talk about OAuth

The first thing you NEED to know about OAuth is that OAuth and OAuth 2.0 are not the same protocol.

From the OAuth guide on hueniverse:

OAuth 2.0 is a completely new protocol and is not backwards compatible with previous versions. However, it retains the overall architecture and approach established by the previous versions, and the same introduction (from the Official Guide to OAuth 1.0) still very much applies.

But, before we get into that, let’s talk a little bit about what OAuth is for.

OAuth basically does two things for a web site providing some kind of service or API that another application might want to use.

  1. It prevents the consuming application from needing to store or have the user’s login and password.
  2. It allows for a scoping of access to the producer’s services.  (For example, a user might be able to login to a site and access all of the features, but an app using OAuth might only be granted permissions to do certain things.)

So now that we know why, let’s talk about how both OAuth and OAuth 2 work from a high level perspective.

From the app developer perspective, the flow goes something like this:

  1. You register your application with the service you want to access and get some unique identifiers for your application.
  2. When you want to access something on the service, you make a request to the service using your unique identifier and telling it where to send the user after they authenticate.  (Usually you would launch a browser window here.)
  3. User will login to the service using the browser window you launched for that service and choose to grant your application certain privileges.
  4. The service will redirect the user to the callback url you provided and include a code you can use to get an access token.
  5. You call the service one more time passing in your unique identifier and the code you got back and the service grants you an access token which you can use to access services you have been granted permissions for.
  6. The next time you need to make a call you can just use that access token instead of going through this whole process again.  (At least till it expires.)

It really isn’t that complicated; the basic idea is that you tell the service who you are and ask the user to authenticate themselves and grant permissions to your application.  Then you prove that you got the response from the server and that it is still you and the service gives you a special pass to access the service.

The real difference between OAuth and OAuth 2 is the protocol itself, not the process.  So this is both good and bad.

Good, because we don’t have to change our process flow and understand something different.

Bad, because we can’t use the same libraries to access an OAuth 2 implementation as we do for an OAuth implementation and vice versa.  There is no backwards compatibility.

For the purpose of this post I am going to show how to use the Leeloo library to connect to an OAuth 2 service.

Connecting to OAuth 2.0

Download the library

The first thing you will want to do is to get the latest version of the Leeloo library.  It has moved to the Apache Amber project, so this link might change, but for now I found the ready to download binaries here.

Configure build path

Once you have the library downloaded you’ll want to add the following jars to your build path:

  • jettison-1.2.jar
  • oauth2-client.jar
  • oauth2-common-0.1.jar
  • slf4j-api.1.6.1.jar

Make initial request for authorization

Make sure you already have a unique client id created with the service you are going to access.  Most services out there like Twitter have a page where you can request one for your application.

Once you have this, you will use this to create a url that you will redirect the user of your application to.

In the code snippet below, I am creating the url and then creating a new Intent in Android that will open a web browser at that url.

OAuthClientRequest request = null;
request = OAuthClientRequest
       .authorizationLocation(authenticationUrl)
	   .setClientId(&quot;&lt;your client id&gt;&quot;).setRedirectURI(&quot;&lt;your redirect url&gt;&quot;)
		.buildQueryMessage();

Intent intent = new Intent(Intent.ACTION_VIEW,
        Uri.parse(request.getLocationUri() + &quot;&amp;response_type=code&quot;));
startActivity(intent);

A couple of things to note about this code snippet:

  • You’ll need to replace client id with your client id and redirect URI with your redirect URI.
  • The redirect URI for an Android application is going to be some protocol that doesn’t really exist, but you can tell your application to respond to.  (We’ll cover that in the next step, but you might have some URI like myapp://oauthresponse)
  • I had to add a “&response_type=code” to the end of my URL because the authentication service required it.  You might have to look and see how the service you are trying to access expects requests to be formed.

Configure your application to respond to your unique URI

In the previous step we had set the redirect to a unique URI like “myapp://oauthresponse”, now you will need to configure the activity you want to handle the response from the service to intercept that protocol.

You can do this by adding an intent filter to that activity like so:

&lt;intent-filter&gt;
	&lt;action android:name=&quot;android.intent.action.VIEW&quot;/&gt;
	&lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
	&lt;category android:name=&quot;android.intent.category.BROWSABLE&quot;/&gt;
	&lt;data android:scheme=&quot;myapp&quot; android:host=&quot;oauthresponse&quot;/&gt;
&lt;/intent-filter&gt;

With this intent filter we are telling our activity to respond to a URI request in the form of “myapp://oauthresponse”.

Configure your activity to respond to handle the intent you registered to receive

Next we’ll want to set up an override in our activity to handle the new intent that will be called on our activity.  We can then pull the code the service gave us out and use that to request a real token.

@Override
protected void onNewIntent(Intent intent)
{
	Uri uri = intent.getData();

   if (uri != null &amp;&amp; uri.toString()
           .startsWith(&quot;myapp://oauthresponse&quot;))
	{
        String code = uri.getQueryParameter(&quot;code&quot;);
        // ...
   }
}

This code will allow us to respond to the intent that will be fired by the web browser when the service redirects the user to “myapp://oauthresponse.”

Exchange the code for a token

Next we need to get a real token instead of a code.  When the user typed in their username and password and granted access to our application, the server called our callback URI with a code that we extracted in the last step.

Now we can pass that code back up to the server along with our client secret and client id and get an access token.

OAuthClientRequest request = null;

request = OAuthClientRequest.tokenLocation(&quot;&lt;service request URL&gt;&quot;)
	.setGrantType(GrantType.AUTHORIZATION_CODE)
   .setClientId(&quot;&lt;your client id&gt;&quot;)
	.setClientSecret(&quot;&lt;your client secret&gt;&quot;)
	.setRedirectURI(&quot;myapp://oauthresponse&quot;)
	.setCode(code)
	.buildBodyMessage();

OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

OAuthJSONAccessTokenResponse response = oAuthClient.accessToken(request);
String token = response.getAccessToken();

In this bit of code we are sending back to the server all the information we have that identifies our application as well as the code that proves the user allowed us to access that service.

Then we get back an access token from the server.  I would recommend you save this access token so that you don’t have to do this reauthentication in the future.

Wrapping it up

So what we have been able to do here is to redirect a user to the right page to authenticate our application, and then wire up our activity to respond to the redirect the service gives us in order to ultimately get an access token we can use to prove we are authorized to access that service on behalf of the user.

Be cautious though, because not everyone is implementing OAuth 2.0 exactly the same way, since the spec is not finalized.  So you might run into issues where things aren’t working exactly as laid out in this post.  If that is the case, you may have to modify a URL that is generated or something along those lines.

In my next post, I’ll show you what you can actually do with your authorization token.  We’ll go through calling a REST based API web service from Android.

Feel free to post any questions in comments.  I used this code to connect to the Dailymile.com API in my PaceMaker application.

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter here.

Published My First Course on Pluralsight

My number of blog posts in the last couple of months has definitely been a little lower than I like, but I have a pretty good reason.

I just got my first course published on Pluralsight!

logomedium

The course is called Android Development for .NET Developers and it covers most of the basic knowledge you would need to go from knowing nothing about Android development to being able to create a fairly simple application and publish that application to the Android Market.

If you haven’t checked out Pluralsight, it is a really good site for a wide variety of developer training videos.  They really managed to get some very good content on the site and there are videos on just about every .NET topic you can think of.

I have also really enjoyed working with the guys that run Pluralsight, they are all very friendly and very knowledgeable.  Thanks to David Starr and Fritz Onion for all their help getting my course ready and published.

You never really learn something till you teach it

teacher-point

This simple truth became more apparent to me than ever during the process of making this course.

I thought I had a pretty good understanding of the Android fundamentals, having published a fairly complex application, PaceMaker.

What I became quickly aware of is that there is a huge difference between having knowledge and having understanding.

I equate knowledge as possessing a formula to be able to do something, but lacking knowing why or how to make modifications to the process.

Cooking provides an excellent example of this.  There are many people in the world who know how to cook a large number of dishes.  But many of these people only have the knowledge of cooking.  They have a large collection of recipes which they can follow to produce the desired result.

A professional chef on the other hand, has a true understanding of cooking.  This person might have knowledge of many recipes, but they also understand why the particular ingredients are used and can make modifications to those ingredients and steps.  They may even create something without preset steps because they understand what they are doing, not just have knowledge about it.

It was great to have the experience of creating these videos because I was able to acquire an in-depth understanding of Android development, not just a knowledge of what to do.

If you ever have the opportunity to teach, I definitely recommend you take that opportunity.  Even if you don’t think you are qualified to teach a subject, by the time you have prepared what you are going to teach, you will be qualified.  Trial by fire perhaps, but well worth the outcome.  Plus you’ll be helping others in the process.

Much harder than I thought

I do have to admit though, recording training videos is definitely much harder than I had originally anticipated.

In order to get 40 minutes of video, it might take 6 hours worth of work or even more depending on the prep work involved and how much editing after getting the raw footage.

I really expected that it would take about as much time as it takes to record something to produce that something, but I definitely learned that is not the case.

I often found that I had to draw a line and stop trying to refine a video because you can literally spend an unlimited amount of time editing and tweaking a video.

Another revelation that might be apparent to everyone else, but was quite an epiphany to me was that you can edit “umms” out of video very easily.  You can’t even notice where they are cut out!  My first video, I didn’t even realize I could edit anything, and I ended up taking like 50 cuts until I could get it right.

Overall though, great experience, lots of fun

I felt like I’ve been stretched in a different direction, as I had never done any video or audio recording before and had never really spent much time in a room talking to myself pretending to talk to other people, but it was a good kind of stretching.

I really actually enjoyed the process and I will definitely be doing more of this kind of work in the future.  Probably going to take a bit of a break before I start my next course though.  I want to make sure I take some time to get a good retrospective of the process and sharpen my saw a bit so my next videos can be even better.

As always, you can subscribe to this RSS feed to follow my posts on Making the Complex Simple.  Feel free to check out ElegantCode.com where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter here.