ServiceConnection and MetaWear

Hi,
I have a class "MetaWear" that extends ListActivity and implements ServiceConnection.
So, I have implemented the Bluetooth well (in fact, I'm able to find the MetaWear) but, I have a problem with the implementation of ServiceConnection.
I have seen some docs but I have still some problems.
For example when I implement onServiceConnection the doc suggest:

private MetaWearBleService mwService;
public void onServiceConnected(ComponentName name, IBinder service) {
mwService= ((MetaWearBleService.LocalBinder) service).getService();
}
When I write it, Android studio told me that cannot resolve "getService()" but I don't understand why.

What I want to do is create a connection with the BluetoothDevice discovered (the MetaWear found).


Comments

  • Besides, if I write:
    MetaWearBleService.LocalBinder binder;
    public void onServiceConnected(ComponentName name, IBinder service) {
    binder = (MetaWearBleService.LocalBinder) service;

    Android Studio give me "Attempt to invoke virtual method 'com.mbientlab.metawear.MetaWearBoard com.mbientlab.metawear.MetaWearBleService$LocalBinder.getMetaWearBoard(android.bluetooth.BluetoothDevice)' on a null object reference". It's seems like I'm not able to call ServiceConnection.
  • Problem solved. 
    I have forget to add:
    "getApplicationContext().bindService(new Intent(this, MetaWearBleService.class), this, Context.BIND_AUTO_CREATE);"
    in the onCreate().

This discussion has been closed.