[Android Apps and Games] Geeks Empire:
KeepNote [AndroidWear][Tutorial][SourceCode]

Android Wearis a version of Google's Android operating system designed for smartwatches and other wearables.

By pairing with mobile phones running Android version 4.3+, Android Wear integrates Google Nowtechnology and mobile notifications into a smartwatch form factor. It also adds the ability to download applications from the Google Play Store.

Android Wear supports both Bluetooth and Wi-Fi connectivity, as well as a range of features and applications. Watch face styles include round, square and rectangular. Released devices include Motorola Moto 360,the LG G Watch, and the Samsung Gear Live.Hardware manufacturing partners include ASUS, Broadcom, Fossil, HTC, Intel, LG, MediaTek, Imagination Technologies, Motorola, Qualcomm, and Samsung.

In the first six months of availability, Canalys estimates that over 720,000 Android Wear smartwatches were shipped.As of 15 May 2015, Android Wear had between one and five million application installations.

### Let Start Coding ###

There is just few different between AndroidApp on Phones & AndroidApp on Wearable.

The most important part is Optimizing User-Interface for AndroidWear & then keep in mind which API not available on AndroidWear. These APIs are not available on AndroidWear

android.webkit

android.print

android.app.backup

android.appwidget

android.hardware.usb

NOTE: Do Not set all processes of your app on SmartWatch Module. Cause there is smaller Battery, Memory& weaker Processor.

NOTE: You should use Android Studio to create AndroidWear App.

(However there is tricky way to use eclipse for androidWear But It s better to migrate to AndroidStudio ASAP.)

- from Bottom to Top

When you want to create New Android Application you can choose AndroidWear App Module then AndroidStudio will add necessary AndroidWear Components and Gradle Config automatically.

But you can add AndroidWear Module manually in your current project.

Go to
File > New > New Module > Select AndroidWear & Next to Finish.

Then you need to add required configuration in your Host Application to Link AndroidWear Module.

Open build.gradle (Module: name-of-project) of Host Application. & Add wearProject to Dependencies

dependencies{
...
wearApp project{':NAME-OF-PROJECT'}
...
}

Then Save & Sync.

Cause I want to focus on AndroidWear Module, Just Compile Phone/Tablet Module & Leave it Alone ;)

Open AndroidManifest.xml & Add Uses-Features & Uses-Permissions

<uses-feature android:name="android.hardware.type.watch" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Then go to res/layout/layout.xml unlike Android App for Phones There is 3 layout.xml for each Activity on SmartWatch.

main.xmlJust Hold the View >>

<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.WatchViewStub
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/watch_view_stub"
android:layout_width="match_parent" android:layout_height="match_parent"
[B]app:rectLayout="@layout/rectangle_main"
app:roundLayout="@layout/round_main" [/B]
tools:context=".WearActivity" tools:deviceIds="wear"></android.support.wearable.view.WatchViewStub>

rectangle_main.xml for Rectangle SmartWatch Display that All GUI components must Add here

round_main.xml for Round SmartWatch Display that All GUI components must Add here

For This application I just set 3 Buttons to Invoke SpeechRecognition Engine, Confirm to Save Note & Cancel. (Check Source Code)

Now I should add functionality to GUI components in Java.Classes.

In Main Activity (WearActivity.java) To Start Speech Recognition Add This Function

private static final int SPEECH_REQUEST_CODE = 0;
private void displaySpeechRecognizer() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
startActivityForResult(intent, SPEECH_REQUEST_CODE);
}

After This I need to get result from engine so i should define onActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
[B]//Here I should Handle Results *[/B]
}

* List<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
final String [COLOR=Red][B]speech [/B][/COLOR]= results.get(0).toString(); // This is the String I must Save to File

Here is Code How to Save File & Write Data into it

//Save Content
try {
FileOutputStream fOut = openFileOutput(NAME, MODE_PRIVATE);
fOut.write(([COLOR=Red][B]speech[/B][/COLOR]).getBytes());

//Always Close All Streams
fOut.close();
fOut.flush();
}
catch (Exception e) {
System.out.println(e);
} finally {}

After Data Saved users will return to App to See their saved Notes.

In This SourceCode I used listView to show all Saved notes But you can do whatever you like.

This Code Help to Read Files Content

//Read-File
public String READ(String S, Context context){
File Fav = new File(S);
String Read = null;
FileInputStream fin;
BufferedReader br = null;

try{
fin = new FileInputStream(Fav);
br = new BufferedReader(new InputStreamReader(fin, "UTF-8"), 1024);
System.out.println(br);

int c;
String temp = "";
while( (c = br.read()) != -1){
temp = temp + Character.toString((char)c);
}
Read = temp;
}
catch(Exception e){
System.out.println(e);
}
finally{
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return Read;
}

For More Detail (Check Source Code)

Download SourceCode & APK & Enjoy

HOW TO Send/Receive Data from AndroidWear SmartWatch.
​

Don't forget to Hit Thanks
​