Compilations error following Android guide

edited April 2015 in Android
Hello everybody,

I am following the Android guide to change the cellbots data logger (updated android-studio version)to a version that also records the accelerometer data from a metawear. I used the android guide to implement all the callbacks etcetera, but I get stuck at the Discovering a Board section. At
final mwBoard = btManager.getAdapter().getRemoteDevice(MW_MAC_ADDRESS)
where I get the error
Error:(140, 22) error: <identifier> expected
Error:(140, 79) error: ';' expected

Even with the obvious ; fixed I get the unexpected identifier error. Furthermore is declared nowhere which seems strange. I put the fully modified version here on GitHub .

I don't know if I am amiss or if there is an error in the Guide which causes these problems. I tried earlier to implement the methods from the SOSTrigger application to connect to a metawear, this failed miserably however at the point I would select a metawear from the list, that is why I resorted to the mac-address solution following the Android guide.

It would be awesome if someone can tell me where I go wrong or how to go right.

//edit: here is the code of the main activity for easy reference:


  • edited April 2015
    so appareantly the line at fault is
    final mwBoard = btManager.getAdapter().getRemoteDevice(MW_MAC_ADDRESS)
    which should be
    final BluetoothDevice mwBoard = btManager.getAdapter().getRemoteDevice(MW_MAC_ADDRESS);

    I think also public final string should be String.
    And there are several references to the metawear controller object with different names (mwCtrllr and mwController).

    My metawear with the current code is still not connecting though (debug log shows only service connect started and connecting... but not "A Bluetooth LE connection has been established!" or "shake detected" which I hoped for.

    new code is on github, pastebin here: , anyone able to tell me why my metawear is not actually connecting?

    ps.Does this forum has code tags btw? I can't find any...

    android-studio also automatically changes
    mwController.addDeviceCallback(new DeviceCallbacks() {
    mwCtrllr.addDeviceCallback(new MetaWearController.DeviceCallbacks() {

  • Looks like I forgot to register with the local broadcast manager, finally working now. Working code up on github and here:

    I think the android guide could benefit from a good update and even more from the full code connecting a metawear (possibly by MAC and/or useing the mwscanner), maybe even a full android project doing nothing but connecting and adding a switch callback or something like that.
  • edited April 2015
    Hmm, logging doesn't start some way, I use this:
    Accelerometer.SamplingConfig config = accelCtrllr.enableXYZSampling().withFullScaleRange(Accelerometer.SamplingConfig.FullScaleRange.FSR_8G).withOutputDataRate(Accelerometer.SamplingConfig.OutputDataRate.ODR_50_HZ);

    and the following callback:
     }).addModuleCallback(new Accelerometer.Callbacks() {
                public void receivedDataValue(short x, short y, short z) {
                    Log.i("logdebug", "received data value");
                    Log.i("logdebug", String.format(Locale.US, "(%.3f, %.3f, %.3f)",
                            x / 1000.0, y / 1000.0, z / 1000.0));

    but I receive no data :(. Full code again: (also pushed to github)

    //edit: for some weird reason it worked after I resetted the metawear, can anyone explain that?

  • edited April 2015
    Thanks for feedback on the docs page.  As for a simple project, the SOSTrigger ( project demos the full code flow.  You can use that as reference for future projects.

    Not sure why you had to restart the board.  Either the API or firmware had bugged out but I cannot think of a reason why based on your use case.
  • I disagree frankly, the code of the metawear specific part of the code is rather cluttered around the rest of the android code concerning texting etc. Also the android guide and the SOSTrigger code are different in ways which make it hard for me, as a novice android programmer to get to grips with the code as a whole. I would have much preferred an example that only gives a simple toast or log when the button is pressed.

    The SOStrigger code also uses the scanner fragment which is not used nor explained in the android guide, which together with the errors in the android guide make it very hard for me to get to a working system (note: it took several days for a rather simple application). The SOStrigger application is also only documented (sparsly) in the code itself, but not anywhere else. For someone to understand the entire flow of code it is much easier to have a basic rundown of the system. The android guide tries to do this but failed in my eyes (giving no clear distinction between the fact that there are different methods, no clear explenation of the bluetooth device select method(s) and no full code overview where all the bits are put together in one comprehensible peace of simple code.)
  • The purpose of the guide is to help users understand the MetaWear library, not teach them about the Android platform.  It is the user's responsibility to have a good understanding of the Android topics (Activity, Service, BroadcastReceiver, etc.) before trying to use the Android library.  

    For example, scanning for Bluetooth devices is a Android task, not a MetaWear specific one.  The scanner fragment you mentioned is derived from the sample code and documentation provided on the Android Bluetooth LE page.  If the code in said fragment makes little sense, then it is up to the user to familiarize himself with the Android BLE stack and related GUI components.
  • I hope marketing agrees with you, since you are basically making it more difficult for the user to use your product. Support is not about shoving off responsibilities to some place else, definitively not the user IMHO.
  • tomzooi,

    We highly recommend taking some Java, and Android Studio basic classes before using the MetaWear. Google provides amazing documentation here:

  • That's an attitude I understand, but not having to do an in-depth study of the Android BLE stack etcetera is what makes an (in this case yours) API powerful and reducing development time.
  • If you were to use an Arduino based solution you would need develop your own API structure to do the callbacks to your board and write both C and whatever code you need on your mobile device etc..  So out of the box it is still easier than a lot of the solutions out there.  The only BLE specific stuff you have to worry about with the Android API is scanning for the device....after that you use the API to connect,  disconnect etc..

    With that being said there is still a learning curve.  All sorts of little things such as needing to remember to disconnect from the board to delete data in the accumulator/logger etc..  This is true with any platform.  

    I can understand where you are coming from as an Android newbie.  Are there other tech stacks,  IE:  Javascript,  Cordova,  Ruby etc. that you are familiar with?  Are you new to mobile development in general?  This could help the team to prioritize other framework support and/or efforts towards creating examples in the future.  

    I am going to be doing a half day session on getting started with the Metawear on Android at Andevcon in Boston in July.  There are going to be a lot of hands on sessions,  so it might be a good way to help kickstart your Android if your up for making that trip.

    Also,  the documents and examples are very much a living breathing thing.  If there are things you have discovered one your journey that could help others I would strongly encourage you to blog about them,  submit pull requests to add better documentation in the example apps as you figure things out etc.. 
  • That it is still easier I grant you, the BLE specific is indeed somewhat independent, however it is basic functionality and therefore is better to document it properly for novice users.

    Second remark: very true, I get that (I am not new to learning new platforms, programming languages etcetera)

    I am familiar with lots of tech stacks, worked mainly on web platforms and linux platforms. Android is relatively new to me in that aspect that so far I only written basic prototype applications.

    Boston sounds nice, but I'm in Singapore until mid July (where I'm doing my internship) then I'm back in NL for holidays and finding a graduation assignment.

    As to the documentation, I mentioned the errors in the documentation in this forum post, at the moment I am to busy to help you guys with documentation.
This discussion has been closed.