1

I am a newbie and I can not seem to get connected to a LightBlue Bean. Below is what I have but mBean.connect(this, myBeanListener); doesn't seem to connect. I keep getting a "Context context" error but this is the example at https://bitbucket.org/littlerobots/beanlib/overview. Can anyone please help? Thanks so much!

BeanDiscoveryListener blistener = new BeanDiscoveryListener() {
    @Override
    public void onBeanDiscovered(Bean bean) {
        mBean = bean;

        BeanManager.getInstance().cancelDiscovery();
        Toast.makeText(getApplicationContext(), "Bean discovered - "+this, Toast.LENGTH_LONG).show();

        mBean.connect(this, myBeanListener);
    }

    @Override
    public void onDiscoveryComplete() {
        int numbre = BeanManager.getInstance().getBeans().size();
        Collection<Bean> beans = BeanManager.getInstance().getBeans();

        Toast.makeText(getApplicationContext(), numbre+" Beans Found", Toast.LENGTH_LONG).show();
    }
};

BeanListener myBeanListener = new BeanListener() {
    @Override
    public void onConnected() {
        Toast.makeText(getApplicationContext(), "CONNECTED TO BEAN", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onConnectionFailed() {
        Toast.makeText(getApplicationContext(), "CONNECTED FAILED", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onDisconnected() {
        Toast.makeText(getApplicationContext(), "BEAN DISCONNECTED", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onSerialMessageReceived(byte[] bytes) {
        Toast.makeText(getApplicationContext(), "Byte - "+bytes, Toast.LENGTH_LONG).show();
    }

    @Override
    public void onScratchValueChanged(int i, byte[] bytes) {

    }
};

private void cancelBeanDiscovery(){
    BeanManager.getInstance().cancelDiscovery();
}

1 Answers1

1

I figured it out, it was mBean.connect(getApplicationContext(), myBeanListener);