Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Create and Run Your First Smart Watch App in 5 Minutes or Less

0.00/5 (No votes)
19 Sep 2015 1  
Build and run a real smart watch app without even downloading an SDK

Introduction

This tip describes a simple technique for building and running a smart watch app in 5 minutes or less. Lacking a smart watch, you can even simulate it in jsfiddle!

Background

Requirements:

  1. A tizen os based Gear Smart Watch, such as the Samsung Gear 2 or Gear S
  2. A very low cost 3rd Party app called APE Pad, available from the Samsung Gear App Store
  3. A PC to connect the smart watch to using USB
  4. Notepad or similar text editor

Even if you do not have a smart watch, you can follow along and run the "smart watch app" on your PC any way.

Step 1 - The First 5 Minutes

Connect your Gear watch to your PC using the USB cable. The Gear watch should show up in File Explorer under this PC. Browse to the watch's Documents Folder.

Step 2

Fire up Notepad. Enter or copy and paste the following text:

alert("Hello World")

Save the file with the name HelloWorld.txt to a convenient location such as your desktop. Notepad will not allow you to save directly to the Documents folder of your watch.

Step 3

Using File Explorer, copy and paste the HelloWorld.txt file to the Documents folder of your watch.

Step 4

  1. Run the APE Pad app on your watch.
  2. Click the Menu Button
  3. Choose File... Open
  4. Choose the file HelloWorld.txt
  5. Click the Menu Button
  6. Choose Run (at the very bottom of the menu)
  7. Your watch will display the JavaScript alert "Hello World"
  8. You should have successfully built and run a smart watch app in five minutes or less!

Step 5, The Next 5 Minutes and Beyond

Although you can conveniently edit and run the JavaScript directly on the watch in APE Pad, you can also edit and test the JavaScript on your PC using JS Fiddle.

  1. Browse to jsfiddle.net
  2. Copy and paste the following code to the HTML pane:
           <!DOCTYPE html>
    <body>
    <p>Click the button to run JavaScript.</p>
  3. Click the jsfiddle Run button to view the Result
  4. In the Result pane, click the Try it button
  5. Click Ok on the resulting JavaScript alert

Time to Get Creative

You can enter almost any valid JavaScript code between the lines //from here and //to here, then test it using the jsfiddle Run button, followed by clicking the Result Try It button. Define code, variables and functions between those 2 lines as needed.

Test until satisfied, then copy and paste the lines between //from here and //to here into Notepad, then save as a txt file. Then copy to the documents folder of the watch, open and run (and edit if desired) in APE Pad.

The following code will use the 4 variables LFt, LIn, WFt and WIn to calculate and display square feet, square yards and square inches. In jsfiddle, or in APE Pad, modify the variable values as desired, then run again!

var LFt = 9
var LIn = 0
var WFt = 12
var WIn = 0

var SF = (LFt + LIn/12) * (WFt + WIn/12)

r = LFt + "' " + LIn + '" x '
 + WFt + "' " + WIn + '"'
 + '\n\n= ' + SF.toFixed(2) + " sq. ft"
 + '\n= '+ (SF/9).toFixed(2) + " sq. yds"
 + '\n= '+ (SF*144).toFixed(2) + " sq. in"
alert(r)

The following code simulates a somewhat sarcastic "magic 8 ball" in either jsfiddle, or in APE Pad.

var answers = [
"As If",
" Ask Me If I Care",
" Dumb Question Ask Another",
" Forget About It",
" Get A Clue",
" In Your Dreams",
" Not",
" Not A Chance",
" Obviously",
" Oh Please",
" Sure",
" That's Ridiculous",
" Well Maybe",
" What Do You Think?",
" Whatever",
" Who Cares?",
" Yeah And I'm The Pope",
" Yeah Right",
" You Wish",
" You've Got To Be Kidding..."
]
alert("Concentrate on ypur question,\nThen Click OK")
var i = Math.random() * answers.length
i = parseInt(i,10)
alert(answers[i])

Points of Interest

Note that there are some, but actually few restrictions on the JavaScript the watches will run.

Notably, they will run the JavaScript alert() function, but not the JavaScript prompt() function.

You can even use the JavaScript Math functions as desired, such as Math.random() as shown above.

If you feel text only apps are too limited, think back to the APPLE ][ and what was possible with it using just simple applesoft basic!

History

This is the first version.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here