B4A Library Wearable DataLayer BETA

First thing first, this is an early Beta for those that wish to start playing with Android Wear. There are things that don't work yet or haven't been fully tested yet (Assets, deleting DataMaps, etc).

Relevant threads:
Tutorial to create a Wear AVD - for if you don't have a device
Tutorial for Creating and Packaging a Wear app - required for the Wear app to install on the Wear Device.

What's included in this thread:
  • The DataLayer Library Beta - this library is what is required for communications between your Handheld and the Wearable
  • Example projects - there are 2 projects, one is the Wearable app and the other is the HandHeld app. The Handheld already has the apk for the Wearable packaged inside so it is ready to go. Compile and install the Handheld project and both parts will install. I've had to upload Handheld project to DropBox for now as it is too big for the forum limits Download Here
In my example apps the handheld has 2 sections. Profile details:- this adds a string (name) and an Int (age) to a DataMap and syncs it, the profile image will be effective once I get Assets up and running. Then there is the message section that sends a one way message.

On Wearable the DataMap is sync'd and the info displayed on an activity and the the messages are shown as Toasts.

First important edit that I felt I had to find 5 minutes to add
The use of this library requires the inclusion of Google Play Services. Similar to the Android-Support libraries, you have to download this with sdk manager and copy the library files over to your additional libraries folder. A typical place for this would be

C:\Program Files\Android\sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs

Although this path may vary dependent on your installation.

It also requires 'AdditionalRes' (see the attributes in the activity module). Again the path may vary. This is just for the Version ID of Play Services.


I will spruce this post up a bit more when I get time.
 

Attachments

  • Wearable.zip
    8.1 KB · Views: 398
  • WearableDataLayerLibFiles.zip
    24.7 KB · Views: 359
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
Reserved
 

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I just started playing with it and here is some things I found so far and to watch out for:

1. When you copy your wear device app to the handheld Objects\res\raw folder make sure you set the wearable_app.apk to 'read only' when you run/compile your handheld app. Other wise you will find the wearable_app.apk gets deleted when you compile the app and it wont install on the wear device. (so easy to forget)

2. If you want to delete the app from your wear device you can't, unless you delete the phone/tablet app and then sometimes you may need to sync the apps using the Android wear app.

I am sure I will find some other things to watch out for but for now that is all I have found.
 

barx

Well-Known Member
Licensed User
Longtime User
Thanks for the pointers @aaronk,

1) this is mentioned in the linked tutorial but always good to re-iterate this points. As you say, very easy to forget. I'm sure this could be covered with Compile Options (or whatever it is called) but I have no experience what so ever with that.

2) This is the way it is with Wear, if you app has a Wear counterpart it is installed from the handheld app and also uninstalled when you uninstall the handheld. If you accidentally end up with an app on there from testing that you installed straight to the Wear device you can remove it using the adb command line tool.

;)
 

appie21

Active Member
Licensed User
Longtime User
i try to start with it too!

but i can't find
rc\barxdroid\wearable_app\main.java:367: error: package com.google.android.gms.wearable does not exist
_item.setObject((com.google.android.gms.wearable.DataMap)(_m.GetValueAt(_i)));

I have changed the directory to my sdk folder, but i can not find com.google.android.gms.wearable

my path is C:\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res
i
What do I wrong?

Fixed i for got the jar files!
 
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
Just updated the library files in the OP. Added a few more features, can now get DataMaps from the Wear Network at anytime:
.GetDataMap for singular
.GetAllDataMaps for all

You can now also delete a DataMap from the Wear Network.

Most things are working now. LocalNodeID will complain about being run in the UI thread as I was trying to do this without the use of a callback event. Looks like I need to do a Callback event for it. I class the library as close to finished now. couple more fixes and the just need to master the Static listenerService for apps to receive data whilst the app is closed.

Note: Some methods / Event signatures may have changed. To be honest I have messed with it that much I cannot remember, lol

I will update the demo apps later.

To be continued...
 

appie21

Active Member
Licensed User
Longtime User
Can't wait to see your demo apps /work!

(at the momend my phone is for repair so i can't test and work with Android Wear :(
 

ykucuk

Well-Known Member
Licensed User
Longtime User
when i try to run sample project i get error :
AndroidManifest.xml:20: error: Error: No resource found that matches the given name (at 'value' with value '@Integer/google_play_services_version').

any help
 

Kevin

Well-Known Member
Licensed User
Longtime User
I think it is related to this:

First important edit that I felt I had to find 5 minutes to add
The use of this library requires the inclusion of Google Play Services. Similar to the Android-Support libraries, you have to download this with sdk manager and copy the library files over to your additional libraries folder. A typical place for this would be

C:\Program Files\Android\sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs
Although this path may vary dependent on your installation.

It also requires 'AdditionalRes' (see the attributes in the activity module). Again the path may vary. This is just for the Version ID of Play Services.
 

ykucuk

Well-Known Member
Licensed User
Longtime User
Hello Kevin,

i download Google Play Services and put it to folder "C:\Program Files\Android\sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs"

what about my additional folder ?

could you give me little bit info
 

Kevin

Well-Known Member
Licensed User
Longtime User
That is the folder where it is commonly found, but you need to copy it to whichever folder you have set up in B4A as your 'Additional Libraries' folder.
 

ykucuk

Well-Known Member
Licensed User
Longtime User
ok . i understand this. Firsti try copy google-play-services.jar file to my b4a add lib folder. Second i copy folder (google-play-services_lib) my b4a add lib folder.
both are with same error when try debug

"
Generating R file. Error
AndroidManifest.xml:20: error: Error: No resource found that matches the given name (at 'value' with value '@Integer/google_play_services_version')."
 

Kevin

Well-Known Member
Licensed User
Longtime User
Did you edit the #AdditionalRes line below in the main activity module to reflect the proper path on your computer where the Android SDK placed the Google Play Services files?

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A WearDemo
    #VersionCode: 1
    #VersionName: 1.0
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #AdditionalRes: C:\Program Files\Android\sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
#End Region
 

barx

Well-Known Member
Licensed User
Longtime User
ok . i understand this. Firsti try copy google-play-services.jar file to my b4a add lib folder. Second i copy folder (google-play-services_lib) my b4a add lib folder.
both are with same error when try debug

"
Generating R file. Error
AndroidManifest.xml:20: error: Error: No resource found that matches the given name (at 'value' with value '@Integer/google_play_services_version')."
There is no need to copy the full folder, just the jar. The error you are getting will be resolved if you follow kevin' s instructions above. (set the additional res path)
 

ykucuk

Well-Known Member
Licensed User
Longtime User
hello again.

my add folder is c:\b4a\libs

i add *jar file to this folder and change code head of module with this path. it gives a lot of error with other libs.

when i change code head of module with c:\b4a\libs\res i got same error like before posts.

i added google play services res folder to my b4a add. lib folder no chance its same

please look to attachment
 

Attachments

  • Screen Shot 2014-10-01 at 13.07.25.png
    Screen Shot 2014-10-01 at 13.07.25.png
    159 KB · Views: 277

Kevin

Well-Known Member
Licensed User
Longtime User
You've still got the #AdditionalRes line wrong. It needs to be the path that the Android SDK manager placed it in and has nothing to do with b4a or its folders. It should look similar to what Barx had but may vary by computer. I think you're merging the two things that need to be done. You've moved the library to the b4a extra libs folder but you also need to reference the original folder as it is in your Android SDK installation.
 

barx

Well-Known Member
Licensed User
Longtime User
Got static listeners working nice now. Not sure if this is the correct term for them. Basically the app can listen for the messages / data changes even when the app is closed. Please correct my term if required, lol. Will hopefully update the attached lib files tomorrow some time. I have the version number @ 0.97 as I fell I am super close to first release version

Just need to test /edit the routines to get the files back out of an Asset.

p.s. I haven't posted an updated demo yet for last revision as I have been concentrating on the lib code. The demo has gotten a little scrappy and needs a good cleanup.
 

Uitenhage

Member
Licensed User
Longtime User
Great Work!

I have taken your demo/tutorial and added some views and even a SQLite database and everything works as I expect it to.

But I can only deploy the watch app if the phone app is compiled as Debug. Is this by design? Just the newness of everything? Going to be fixed soon?

Thanks,

Jim
 

barx

Well-Known Member
Licensed User
Longtime User
Really struggling to get time to finish this off. Just the matter of getting image / file from the Assets on the 'other' side.

The code is here is anyone can follow it enough and wishes to collaborate I may be interested ;)

https://github.com/oobarxoo/WearableDataLayer/tree/master/src/barxdroid/wearabledatalayer

If not, no worries I will get around to it soon enough.

The GetBitmapFromAsset may even work. I can't remember how it turned out after last edit a couple of weeks ago :oops::eek::confused:
 

Ph1lJ

Member
Licensed User
Longtime User
I have attempted to compile the sample supplied, having copied the .jar files and modified the Additional Res line in the Project attributes but I get the following error, when compiling the wearable app


Parsing code. 0.01
Compiling code. 0.01
Compiling layouts code. 0.01
Generating R file. 0.49
Compiling generated Java code. 2.25
Convert byte code - optimized dex. Error
A referenced library is missing: android-support-v4

Anyone have any ideas
 
Top