admin 管理员组文章数量: 1086019
2024年3月26日发(作者:通达oa2017版官方下载)
;
ption;
;
or;
;
;
ty;
ssDialog;
othAdapter;
othDevice;
othSocket;
astReceiver;
t;
;
Filter;
;
r;
e;
publicclassOtherextendsActivity {
publicstaticfinalUUID MyUUID = UUID
.fromString("00001101-0000-1000-8000-00805F9B34FB");
privateBluetoothSocket btSocket =null;
privateBluetoothAdapter adapter =
aultAdapter();// 获取蓝牙设备
privateSet
privateBluetoothDevice device;
privateBluetoothDevice btDev;
privateProgressDialog bluetoothPro;
privatebooleanbluetoothstause =true;
privateIntent recalled;
privateconnectbluetooth connectdevice =null;
privatevolatileboolean_discoveryFinished;
privatediscover myDiscovery =newdiscover();
publicvoidonCreate(Bundle savedInstanceState) {
te(savedInstanceState);
setContentView();
// 获取当前已经配对的设备
devices = dedDevices();
// 创建一个进度条
bluetoothPro =newProgressDialog(this);
// 如果已配对的设备大于0 就查找到目标设备并且开始连接 如果没有找到到
设备就开始搜索
if(() >0) {
intcnt =0;
for(Iterator
.hasNext();) {
device = (BluetoothDevice) ();
if(e().equals("PC-60NW")) {
cnt++;
bluetoothConnect(device);
break;
}
}
if(cnt ==0) {
// 没有以配对设备 开始搜索
n("配对设备中没有找到目标设备 开始搜索");
Discovery();
}
}else{
// 没有以配对设备 开始搜索
n("没有以配对设备 开始搜索");
Discovery();
}
}
// 搜索设备开始的函数
publicvoidDiscovery() {
/* 注册接收器 */
IntentFilter discoveryFilter = new IntentFilter(
_DISCOVERY_FINISHED);
registerReceiver(_discoveryReceiver, discoveryFilter);
IntentFilter foundFilter = new IntentFilter(
_FOUND);
registerReceiver(_foundReceiver, foundFilter);
// 再次去确定蓝牙设备状态
if (!led()) {
();
}
// 设置进度条显示的提示信息
sage("");
();
// 启动线程开始搜索设备
版权声明:本文标题:蓝牙代码 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1711397866a592074.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论