1

我是新手,我似乎无法连接到 LightBlue Bean。下面是我所拥有的,但 mBean.connect(this, myBeanListener); 似乎没有连接。我不断收到“上下文上下文”错误,但这是https://bitbucket.org/littlerobots/beanlib/overview上的示例。有人可以帮忙吗?非常感谢!

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();
}
4

1 回答 1

1

我想通了,是 mBean.connect(getApplicationContext(), myBeanListener);

于 2014-11-11T03:00:11.147 回答