一, ivt bluesoleil 蓝牙驱动(window7 64位 要下载64位的驱动)。SSCOM32 蓝牙串口。 插上蓝牙模块, 安装好这两个软件就可以在电脑模拟蓝牙发送数据。二, window7 中,插上蓝牙模块 但是桌面右下角却没有显示,可能原因 :
1,控制面板-》管理工具-》服务中 Bluetooth support service 没有启用,可启用并改为自动
2,把蓝牙定义为“显示图标和通知”如果仍不显示 则:网络和共享中心 --- 更改适配器设置 ---- Bluetooth网络连接 ---右键“属性”---Bluetooth 选项卡 ------Bluetooth设置---- 选择“在通知区域显示Bluetooth图标”
三,蓝牙初涉:注意添加蓝牙权限
1, /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button blueToothBt = (Button) findViewById(R.id.main_bluetooth); blueToothBt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // 获取BlueToothAdapter对象 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); // 判断adapter是否为空,为空说明本机没有蓝牙设备 if (adapter != null) { // 判断蓝牙设备是否可用 if (!adapter.isEnabled()) { // 创建一个intent对象,提示用户开启蓝牙设备 Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivity(intent); } Set<BluetoothDevice> devices = adapter.getBondedDevices(); if (devices.size() > 0) { for (Iterator<BluetoothDevice> iterator = devices.iterator(); iterator.hasNext();) { BluetoothDevice device = iterator.next(); Log.i("MainActivity", "远程蓝牙设备地址" + device.getAddress()); } } } else { Log.i("MainActivity", "本机没有蓝牙设备"); } } }); }
2,Button deviceVisibility = (Button) findViewById(R.id.bluetooth_device_visibility); deviceVisibility.setOnClickListener(this); // 创建一个过滤器,将action指定为 BluetoothDevice.ACTION_FOUND IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); receiver = new BlueToothReceiver(); // 注册广播接收器 registerReceiver(receiver, filter); adapter = BluetoothAdapter.getDefaultAdapter(); Button deviceScan = (Button) findViewById(R.id.bluetooth_scan); deviceScan.setOnClickListener(this); } private class BlueToothReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub if (intent.getAction().equals(BluetoothDevice.ACTION_FOUND)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); Log.i("demo2", "扫描到的设备地址" + device.getAddress()); } } } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { // 设置蓝牙设备可见性 case R.id.bluetooth_device_visibility: Intent visibilityIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); // 设置可见状态的持续时间,默认是120S,超过300S 会被 覆盖为最大值300S visibilityIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 200); startActivity(visibilityIntent); break; case R.id.bluetooth_scan: //异步任务 开始扫描,每扫描到一个设备,就会自动发送一条广播 adapter.startDiscovery(); break; } }