我有BLE的主要活动,我有另一个经典蓝牙课程。 我不知道如何同时运行这两个并将它们连接起来。 请建议我。
如果你能给我一些链接或什么
更新:我的应用程序用作支持BLE的两个设备之间的媒介
所以我需要编写一个代码,它可以从发送方获取数据并将其推送到接收方。多数民众赞成
我正在使用nexus 7(中型),眼镜(接收器)和微控制器(发送器)
答案 0 :(得分:0)
将经典蓝牙类 活动对象的构造函数添加为参数,并将其分配给可验证的对象。从活动创建经典蓝牙类的对象时,只需将引用传递给当前对象(活动)。这样,只要您想从经典蓝牙类访问活动组件,只需使用活动参考。
例如:
public class Bluetooth {
private Activity activity;
...
public Bluetooth(Activity activity){
this.activity = activity;
}
}
在Activity类中:
Bluetooth bluetooth = new Bluetooth(this);
答案 1 :(得分:0)
You normally do something like this in your activity:
MyBLuetoothClass mbc = new MyBluetoothClass();
mbc.doStuff();
But it would be helpful if you could provide some code.
Your util class where you want to call methods on can look like this:
public class MyFancyUtil {
// This is your constructor
public MyFancyUtil(){
}
public boolean yourFancyMethod(){
// Do whatever you want.
}
}
In the Activity you just instantiate and use it like:
// Instantiate
MyFancyUtil util = new MyFancyUtil();
// call some method
util.myFancyMethod();