Step by Step Guide on How to Build Your first Samsung Gear 2 App (Tizen)

gearimage

Photo Credit : Samsung Developers
Update : This post created May 12, 2014 when there was mighty little documentation out there, and a lot has changed since then! Samsung has released several new wearable devices, and the SDK (and its installation process) has also changed. While this post still gives an idea of the structure of wearable apps, much of its content may now be stale. To ensure you have the latest stuff .. please go to http://developer.samsung.com/gear . Happy coding!

This post documents the process of installing the Gear 2 sdk’s , running and testing the Hello World App for  Samsung Gear 2 which is based on Tizen. No direct Step-By-Step tutorial is available on the Samsung Gear website and the Getting Started document can be fairly difficult to follow hence this tutorial. Even more confusing, especially for developers new to android and Samsung app development is “how to test the app in a simulator” especially if you do not have a Samsung device and gear smartwatch. 

Clearing up a few Misunderstandings

– Samsung Gear 2 and Samsung Gear 2 Neo are different from the original Samsung Gear in that they run the tizen OS as opposed to the android OS on the orginal Samsung Gear.

See : Android Wear Vs Tizen for Wearables, what developers should know.

– Gear 2 Apps are written in HTML5 (a mix of html, javascript, and css) instead of java which was used for the original Gear apps . For Tizen developers who may be used to developing in C++, sorry, this is NOT supported. ONLY Htlm5.

– The Samsung Gear SDK for android was never really released. While there are a few other samsung accessory services (e.g s pen sdk, group play, AdHub) that are android based, Gear 2 apps are different and must be developed using the Tizen IDE (more on this below)

– In developing and testing connected apps for Samsung Gear, you can either use a real Samsung device and a real gear 2 device , or a real Samsung device and the gear emulator. Currently, using an android emulator and a gear emulator is not supported. More on this is explained below.

See: How to Access Sample Apps and Code for Gear 2 

– The Tizen OS is different from the Tizen for Wearable OS. While the Tizen OS is a full featured mobile OS with features like wifi, carrier mobile service support, C++/C native app + HTML5 support, the Tizen for wearable currently supports only HTML5 and no wifi or carrier service support.

Understanding the Structure of a Samsung Gear App

Samsung gear apps follow the producer consumer model where the producer is an app running on a Samsung Host device (phone or tablet) , and the consumer is a widget app running on the Samsung Gear smartwatch. More explanation from the Samsung device below.

The host device runs an application called the Gear Manager, which communicates with the WearableManagerService running on the Gear. Applications intended for Gear has two parts, one of which runs on the host, called the Host-side Application. This installed application will include an application widget intended for the wearable device, called the Wearable-side widget. The Host-side application generally serves a “provider” function, while the Wearable-side widget generally serves a “consumer” function (these functions will be described in more detail later). During the installation of an Host-side application which contains a Wearable-side widget, the Gear Manager sends the Wearable-side widget to the WearableManagerService on the wearable. The WearableManagerService then installs the Wearable-side widget.

Whilst there is the opportunity to develop applications that take advantage of these two parts, you still have the choice to develop 3 types of apps . Linked Apps, Integrated Apps, and Standalone Apps.

Linked (Master-Follower) Type
The linked Gear application is not included with the general host application. You must install the general host application and the wearable-side widget separately. This is useful if the host application is optional for the gear app.

Integrated Type
In an integrated Gear application, the host-side APK contains the app that runs on both the host devices and the wearable side gear app. When you download an integrated Gear application, the general host application in the host-side APK is installed simultaneously with the wearable-side widget. You should use this type of development if your wearable-side app requires the host portion. E.g a news feed app on a smartwatch cannot connect to the internet and must rely on the host side app to “feed” it the news updates.

Standalone Type
You can use the standalone type, such as a Clock app, when your Gear application does not need a general host application, and can operate independently.

Now that we know a Gear app has two parts, the question is how do we develop each part. Turns our you can use your usual Eclipse environment for developing the host device app (an android ), and you also use the Tizen SDK to build the consumer widget running on the smartwatch. We will illustrate this using the HelloAccessory sample application on the samsung developer website.

Step 1 – Download and Install the SDKs

For the host app development, I suggest you get a copy of eclipse IDE for Java (I already had one) and install the Samsung Accessories plugin . You can use the install new plugin eclipse menu option (Help > Install New Software) and add the Samsung Accessories repository link – http://developer.samsung.com/smsdk/repository/samsung-sdk . Install the entire content of the repository

samsungsdk

Next download and install the tizen wearble sdk install Manager . MAKE SURE YOU DOWNLOAD THE SDK FOR WEARABLE AND NOT THE REGULAR TIZEN SDK … I made that mistake earlier.

However, I still ran into the following error while installing Tizen on a windows 8.1 64 Bit Machine

cannot execute java even if it was installed

After verifying the JAVA HOME variable, path variable and ensuring that any x86 version of java on my machine was uninstalled, it still gave the same error. I however got it to install using some strange hack I found here.

– First, open the windows command line console (cmd) and navigate to  \AppData\Local\Temp\tizensdk_2014xxxxxxx . This folder is usually under Users\YourName\AppData …..
– Next, try to locate the downloaded tizensdk folder and install its jar using java commands.
– Type in: java -jar InstalManager.jar

And another error popped up ..

cannot find repository ..

tizenwaerableerro

To fix that, I did the following .

– Download the tizen wearable sdk image . This is different from the install Manager we downloaded above.
– Click on Advanced > SDK Image > Select the image you downloaded in the previous step . Next .. next … next

tizenwaerableerro2

And that got it installed. On to the next step.

Step 2 – Import Sample Projects – HelloAccessory Sample

Download the HelloAccessory sample project that demonstrates sending a string between a samsung device and a gear. This zip folder contains a source folder with two sets of source code . Staying true to the producer consumer paradigm, the first source folder “HelloAccessoryConsumer” is for the gear device widget and should be imported into your installed Tizen SDK IDE as a project. The other folder “HelloAccessoryProvider” is an Android eclipse project for the host app running on the samsung device. You may import it into your eclipse IDE as an android application.

Step 3 : Build the Tizen HelloAccessoryConsumer Widget

After importing the HellowAccessoryConsumer into your tizen wearable IDE, right click on the project and select build. After successfully building the project, the HelloAccessoryConsumer.wgt is created .

tizenwaereclipse

This represents a standalone .wgt file than can be uploaded into your samsung Gear 2 and installed. To learn more about standalone apps , you can peruse the large collection of sample gear 2 sample apps that come with the tizen for wearable IDE.

See : How to install standalone wgt apps on a gear 2 device or emulator. 

Step 4 : Build the Android Host Section Part.

Remember the three paradigms of apps (Linked, Integrated and Standalone) ? In this step we will be building the android host app that constitutes a part of the the linked and integrated type of apps.

Now copy the .wgt file which you have generated from your tizen project into the assets folder of your HelloAccessoryProvider android project and build it to generate an apk. The idea here is that after you install the HelloAccessoryProvider apk it automatically installs the consumer widget on a connected gear 2 device. The pre-condition is that gear manager must be installed on the device.

Step 5: Testing Your Gear-side app on Tizen Wearable Emulator.

As always there are two methods to test apps. Using live devices (Galaxy S5 and above) and a Gear 2 smartwatch, or using emulators. I’ll focus on how to get this done using emulators as I don’t have test devices at the moment.

First, we create a wearable emulator using the IDE connection explorer
Emulator Manager > Create New VM > Enter name etc … click the play button to launch emulator.
tizenemulator

To run the consumer app, Right Click on the project > Run as Tizen Wearable Web Application . All running now!

tizenemulatorwatch

 See Also : Creating gestures for your Gear 2 apps (swipe, pinch, rotate, double tap, etc)

Step 6 : Set Up An Android Device to Communicate with the Tizen Emulator

Update : It appears the tizen emulator will ONLY communicate with Samsung Gear compatible  devices . I have tried unsuccessfully to get this running on my trusty Samsung Galaxy s2 running CM11.

The Samsung Gear Compatibility list is :

Samsung Galaxy S5 / Galaxy Grand 2 / Galaxy Note 3 / Galaxy Note 3 Neo / Galaxy Note 2 / Galaxy S4 / Galaxy S3 / Galaxy S4 Zoom / Galaxy S4 Active / Galaxy S4 mini / Galaxy Mega 6.3 / Galaxy Mega 5.8 / Galaxy Note 10.1 (2014 Edition) / Galaxy NotePRO (12.2) / Galaxy TabPRO (12.2/10.1/8.4)

Now that we are sure the tizen emulator works, we’ll set up any android device to act as its host device. This devices may also be a real world android phone connected via usb .
Samsung provides some guidelines on how to get this done . There are three apk files you need to install on your android device . You can find them under – Applications for Emulator –  on the Samsung Gear developer page .  SAccessoryService_Emul.apk , SAFTCore_Emul.apkHostManagerForEmul.apk . Download and install them via ADB in this order . To do this, ensure you have added ADB to your system path, navigate to the extracted Applications for Emulator folder and type

– adb install  SAccessoryService_Emul.apk .

Do this for all three files in the order above.

Now, launch the HostManagerforEmulator app which should now be visible in your app drawer list.

emulatorhost

Next, enter the following command in adb

“adb –d forward tcp:8230 tcp:8230”

This should change the hostManager status to connected. Once this is done, you can now run the HelloAccessoryProvider apk in the host device and it should be able to communicate with the tizen emulator HelloAccessoryConsumer widget.

Testing Using the Samsung Remote Testing Lab

Another final way to test your app is to use the Samsung Remote Testing Lab . You will need to create a Samsung Account, and will be allocated an elaborate testing quota each day.

The Remote Test Lab service enables developers to access Samsung mobile devices through the web and to install and test applications on the devices. This is not only the most effective and easiest way to test the compatibility of an application with Samsung mobile devices but also the best way to cut down on hardware costs for test devices. Interaction with the device is performed over the network in real time allowing you to comprehensively test your application before distributing it.

A Few other Errors Encountered Along the Way and FAQ

Windows Critical Structure Corruption

The Tizen SDK installs intels hardware acceleration manager (Intel HAXM) and the idea is to help speed up the performance of the emulator. For some reason installing this leads to a blue screen of death (BSOD) while running the emulator and the error

WINDOWS CRITICAL STRUCTURE CORRUPTION .

I attempted to install a fix from intel that can be found here .. which caused the wearable emulator to just stop working. In the end I just uninstalled the intel haxm software from control panel. Emulator was slower, but BSOD did not happen again.

Problem Loading Perspective

Naturally, Tizen IDE crashed (because of the BSOD error above) while running the wearable emulator. After I launched the IDE, the tizen web perspective just didn’t load up again and gave an error.

problem loading perspective

To fix it, I deleted my workspace folder, closed and restarted the IDE.
If this does not work, delete the entire Tizen wearable sdk folder and re-install the IDE (using step 1 above). This means you have to perform all your imports again. You may back up your .metadata file in your workspace before a crash and replace it after a crash.

Can I Install the HostManagerEmulator apk on a Non-samsung Phone ?

As of the time when this article was written, it is not possible (based on tests I have run) to test your Gear 2 apps using a non-samsung-gear-compatible android host device.  I used a Samsung Galaxy s2 running CyanogenMod 11. First I tried installing the apk’s using adb .. flat out didn’t work – “App Not Installed” . They I tried to brute force the installation by installing the apk’s sequentially in the android systems folder. Hostmanager actually got installed but kept crashing. Apparently there are a few dependencies only available on the Gear-compatible samsung devices. I have also asked and posted on the samsung developer forum and the current consensus is that it is not supported. For now, the best bet to test linked apps is to use the Samsung Remote Testing Lab.

Final Note

What has been your experience ?  Do you own a Gear compatible device and have successfully conducted tests ? Feel free to share your experiences below.

 

 

 

About Vykthur

Mobile and Web App Developer and Researcher. Passionate about learning, teaching, and recently - writing.
This entry was posted in Android Tutorials, Programming, Tutorials, Wearables and tagged , , , , . Bookmark the permalink.
  • stationstops

    “Next download and install the tizen wearble sdk install Manager . MAKE SURE YOU DOWNLOAD THE SDK FOR WEARABLE AND NOT THE REGULAR TIZEN SDK … I made that mistake earlier.”

    God bless you for these two lines of text – I downloaded both, and have been using the regular one for weeks on a project (because I pinned it to my dock right away) – insipidly, one *can* develop web apps for Gear 2 and install them with the regular SDK (using the web simulator) – but only after an enormous amount of confusion, erratic behavior, and hacking.

    Thank you!

    • Vykthur

      Hi Stationstops,

      I am quite glad that was of help to you! Just like you, found that I couldnt access any sample apps or get simple things done … and then bam … I discovered there was a different SDK for wearable.

      Goodluck with your development!

      -V.

  • Govindaraj Kathirvel

    Hi,

    Are there any sample to use Phone Gap as Host application (Hybrid HTML5 + Web SQL along with Java provider application)

    Thanks,

    • Vykthur

      HI Govindaraj,

      At the moment there are no Phone Gap samples available. Will update you as more information comes up. In the mean time, you can post about it on the official samsung developer forum http://developer.samsung.com/forum/en

      Regards,
      V.

  • Eriksen

    What about standalone apps for the Gear 2 and NEO?

    • Vykthur

      Hi Eriksen,

      Thanks for your very important question. It appears I didnt carefully distinguish between the types of apps avaialble (Linked, integrated and standalone) . I have updated the article.

      Regarding standalone apps, you can develop them independently using the tizen for weaarable sdk. Create new project > wearable .. and you are good to go.

      You can also look at the article on running sample standalone apps as well as testing 3rd party apps on a gear 2 or emulator.

      http://denvycom.com/blog/samsung-gear-2-tizen-wearable-sample-apps-widgets-and-templates/
      http://denvycom.com/blog/how-to-install-wgt-files-gear2/

      Regards,
      -V.

      • Eriksen

        Thanks for a thorough update on a bit sloppy question!

        Do you know where it’s stated all peripherals one have access to in standalone mode? I can only find standalone mode mentioned in small sections with not much info.

        I want to make a standalone app which can connect to a bluetooth 4.0 sensor of my own.

        Great article.

        • Vykthur

          Soo … the rules or connection and pairing given by samsung are as follows ..

          Gear 2 devices can ONLY pair/connect with supported Samsung Devices.

          Currently, I dont think you can connect to a 3rd party bluetooth device

          -V.

          • Eriksen

            But then what about the standalone music player? It can connect to bluetooth headsets. Should be fair to call that a third party device, shouldn’t it?

          • Vykthur

            Hi Eriksen,

            You make a mighty point there. I am inclined to believe that the music player app is allowed this priviledge because it is a preloaded app. I need to double check that developers have access to paired bluetooth sensors … and how this is done ..

            I have made a quick post on the samsung dev forum …
            http://developer.samsung.com/forum/board/thread/view.do?boardName=SDK&messageId=266420&startId=zzzzz~

            You can monitor it for any updates.

            regards
            V.

  • Akash

    Hello, I follow your step to run HelloAccessory application. I successfully configure emulator. I am using Samsung grand 2. When I run HostManagerForEmul app it show connected. but when I run “HelloAccessoryConsumer” in Gear2 emulator it shows following error in console ” js/main.js (44) :err [undefined] msg[undefined] ” . could you please help ?

    Thanks

    • Akash

      Ok, I successfully run the HelloAccessory application. I download fresh HelloAccessoryProvider.apk and HelloAccessoryConsumer.wgt from samsung gera2 developer forum. But I want to know that when I edit HelloAccessoryConsumer application and build this , after that I copy paste HelloAccessoryConsumer.wgt in asset folder of HelloAccessoryProvider project and build and run the provider application. After editing the consumer application I can not run the application it gives ” js/main.js (44) :err [undefined] msg[undefined] ” error. Is there any signing problem or something else ?

  • pRo_lama

    Will this also work with Galaxy Gear 1 with TizenOS or is this only for Gear 2 ???

  • Bhadresh Devani

    Hi first of all thanks for such a great tutorials

    I follow your all steps to run SAPSample application which dowload from http://developer.samsung.com/events/developer-blog/blog/Tutorial-How-to-build-a-Basic-Integrated-Gear-Application but when i install it in my samsung s4 mini GT-i9192 then start HostManagerForEmul it always display Disconnected. Even i also start gear emulator and install consumer application it.

    Please help me.

    • Vykthur

      Hi Devani,

      Did you do the tcp forwarding process on adb
      “adb –d forward tcp:8230 tcp:8230”

      This is the critical step that changes the HostManagerForEmul to connected.

      V

      • Bhadresh Devani

        Yes , I do tcp forwarding..

        When i repeat all the steps for begging then it works.

        Thanks for your response

  • Bhadresh Devani

    Hi Vykthur

    It possible to develop such a application that starting communication for host side?

    I want to develop application which send alert message from android side to gear device when specific time arrived. If so then please give me your input.

    Thanks again for your quick response

  • Akash

    I follow this tutorial series to develop a tizen Gear2 application. My application works successfully when I run gear application in emulator. My Gear2 application can create connection and send simple text to android application successfully. But problem occurs when I run my Gear2 application in actual Gear2 Device. My Gear2 application can not create connection with my android application. [ But Gear manager show that Gear2 device is perfectly connected to android mobile device, other Gear2 integrated application works]

    Is my problem in serviceChannel id ?
    Where is my problem ? Please help me.

    Thanks

    • Vykthur

      What error does it display ? Can you post any error that shows up on logcat or the javascript console ?

  • Eir

    I’m having problems connecting my Samsung Galaxy S3 with the emulator. The host manager app stays “Disconnected”. I really have no idea how to fix this. I’m thankful for any suggestions.

    • Vykthur

      Are you able to view your device on adb ? i.e after running adb devices ?
      Also, have you done tcp forwarding ?
      “adb –d forward tcp:8230 tcp:8230”

      • Eir

        Yes, I’m able to see my device via adb. Its the only device attached. After executing the forward command (as you wrote it), I can see the forwarding correctly configured via the adb forward –list command

  • Yogi Salomo Mangontang Pratama

    Hello,

    Thank you very much for the tutorial.

    But I got some trouble when following this tutorial.

    I have followed this tutorial from beginning to the end and already succeeded running the application in Android (Phone) and Tizen (Gear Emulator).

    But one day I uninstalled the Gear Manager App from my phone and now I cannot install the SAccessoryService_Emul.apk , SAFTCore_Emul.apk, and HostManagerForEmul.apk anymore.

    I have uninstalled all three of that application I had before but still I cannot install the new one.

    Could you please give me solution/hint? I have done some research trough google but the result is not satisfying.

    Thank you very much.

  • rrTenz

    I installed the 3 apk’s and then tried to run the “adb -d forward tcp:8230 tcp:8230” command. When I do I just the list of available adb options, as though I typed in “adb -help”. Am I doing something wrong?

  • Seemanta Saha

    Hello, thanks for the tutorial.
    But, I added some activities with provider side service in android application. Everything is working fine.

    But, whenever I close the application from task manager, the service on android side
    which connects with gear side widget get stopped. If I again run the
    apk, the service is not started.

    How can I keep alive the service in android side to receive action from gear side widget when i close the application from task manager.

    Kindly help.

  • Prateek Aggarwal

    We have downloaded the sample HelloAccessory Project from Samsung Developers Website.

    This zip has all these :

    HelloAccessoryProvider / HelloAccessoryConsumer/ APK which has .wgt file in assets folder

    First we did connect Samsung Galaxy Gear(Wearable) with Samsung Galaxy S3 (device). Gear Manager app was installed on S3 and bluetooth connection was established.

    We followed with the document. We installed SDK_HelloAccessoryProvider.apk on S3 and after installation HelloAccessoryConsumer should appear in “My Apps” under GearManager but that’s not happening.

    Trials we had done :

    We had restarted the device and even established the bluetooth connection again with Gear but HelloAppConsumer never appeared in GearManager.

    Help us why we are stucking at the first step itself. we are planning to write more dynamic UI’s for Gear.

    Looking forward to get any replies as soon as possible.

    Adding to the above message :

    Our Samsung Gear is running on Android 4.2.2.

    Is it mandatory to be on Tizen to push the apps on Wearable through Gear Manager ?

    Is certificate needed to install apps on SmartWatch via installing an APK manually ?

  • Great, just what was missing in the Samsung SDK documentation.

  • muhammad tayyab

    i want to install stand alone app on gear 2, i have been looking this for 3 days. anyone can help?