Android: Determining if a Wearable Device is Connected

I'm playing around with developing an application that integrates with the new Android Wear API. In my case I don't want to perform certain actions locally if a wearable device is connected. So this is how you can detect if a device is connected. You would have this code included in the Main Activity of your primary (phone) application: