Wednesday 1 April 2015

Creating App for Wearables



# Use Android Studio.(Recommended)
  •  Create Android Project
  •  Select Phone & Wear project
  •  Follow the steps for project creation wizard.
  • Design your layouts for both mobile and wearable in respective projects.

Now Problems that come when working with wearable

Firstly you need to install Android Wear Companion app on your device in order to make the device and wearable communicate.Which you can download from : https://play.google.com/store/apps/details?id=com.google.android.wearable.app

How to test the wearable app :

Now you need not to have a wearable device (Smartwatch) to test your app. You can test your app on the emulator.Create a wearble emulator using AVD.

Now open the android wearable app in the device and make sure your device is connected to system.After this you will see the welcome screen then select connect with emulator option from the action bar.After selecting the option simultaneously run this command inside i.e command prompt in windows or terminal in Mac in order to make device and emulator connected with each other.

adb -d forward tcp:5601 tcp:5601

Now after this you will see device and wearable emulator are connected with each other.Now whenever you install the Signed apk on device it will sync wearable apk for same onto emulator.

And if your app is not syncing to wearable device or emulator then make sure below points are corrected in your project :

Most of us face a common problem i.e apk file is not automatically installed on wearable when installed on Phone.Frankly i was troubled alot with this one.
But i got it right after few mistakes So do perfrom these steps in order to make app automatically installed as done installing on phone.

Step 1 : 

All the permissions defined in the wear app manifest file should be present in the mobile app manifest file.And you need not to put all phone permissions in wearable manifest.

Step 2 : 

Secondly  In build.gradle file of your phone app Confirm this

dependencies {
    wearApp project(':wear') // You should mention the exact name of the wear app folder here
}


Step 3 : 

Package name : In manifest file for both mobile and wear app should be same.
Application ID : (build.gradle file) of mobile and wear app should be same.


Now if you want to test app on wearable device then follow these instructions :
Firstly enable developer options in your wearable device as we do in device.
then enable debuggin over bluetooth in wearable under developer option.


Now On the handheld, open the Android Wear companion app then Tap the menu on the top right and select Settings.
Enable Debugging over Bluetooth. You can see the status :
Host: disconnected // this will be connected when we run the command to connect both device and wearable
Target: connected

To Connect the handheld to your machine over USB and run:

adb forward tcp:4444 localabstract:/adb-hub
adb connect localhost:4444

Then under settings in companion app you will see following status :
Host: connected
Target: connected

You can also check the connected devices in command prompt in Command prompt by using following command :

adb devices

Finally when you are done with the development of the app then you can generate a signed apk which will be installed on phone and automatically installed on wearable device.
Make sure that build generated is Signed then only it will be installed on wearable.

To generate signed apk Android studio provide us the simple wizard to do it. Well there are other ways available to generate the signed apk but prefer this.
Click on Build, Then select the Generate Signed apk option and go through the wizrad And you will get the signed apk.


Sometimes your app may take time to get Synced to wearable after installation on device so be Patience.And you can always sync manually app to wearable by using sync apps to watch option in android companion app under settings section.


Happy coding!!!
Cheers!!!

No comments:

Post a Comment