蓝牙开发总结

来源:互联网 发布:汉语语法 知乎 编辑:程序博客网 时间:2024/05/21 19:31

1.Android开发
使用android自带的开发包

btAdapt = BluetoothAdapter.getDefaultAdapter();btAdapt.startDiscovery();IntentFilter intent = new IntentFilter(); intent.addAction(BluetoothDevice.ACTION_FOUND);intent.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); intent.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED); intent.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); registerReceiver(searchDevices, intent); intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);device.getName();btSocket = btDev.createRfcommSocketToServiceRecord(uuid);btSocket.connect();

2.J2ME使用blueCover开发包
try { localdev = LocalDevice.getLocalDevice(); } catch (BluetoothStateException e) { System.out.println("ERROR: cannot access local device"); }DiscoveryAgent agent = localdev.getDiscoveryAgent(); try { agent.startInquiry(DiscoveryAgent.GIAC, listener); } catch (BluetoothStateException e) { System.out.println("Device unable to inquiry"); System.exit(2); }

3.C#使用的蓝牙 InTheHand.Net.Personal dll
_NearbyDevices = new List(); BluetoothClient cli = new BluetoothClient(); BluetoothDeviceInfo[] devices = cli.DiscoverDevices(); if (devices.Length == 0) { mybluetooth = false; } foreach (BluetoothDeviceInfo d in devices) { _NearbyDevices.Add(d); mybluetooth = true; } return _NearbyDevices;

// -------------------------12 -27 finish-----------------------------------------
 //注册Receiver来获取蓝牙设备相关的结果

IntentFilter intent = new IntentFilter();registerReceiver(searchDevices, intent); //蓝牙uuid UUID uuid = new UUID(0x0000110100001000L,0x800000805F9B34FBL);//connect 前必须先完成createBond btSocket = btDevice.createRfcommSocketToServiceRecord(uuid); btSocket.connect();


// 广播pin
 
<receiver android:name="com.sceec.MainInterface">    <intent-filter>    <!--   <action android:name="android.bluetooth.intent.action.DISCOVERY_COMPLETED" />      <action android:name="android.bluetooth.intent.action.DISCOVERY_STARTED" />      <action android:name="android.bluetooth.intent.action.NAME_CHANGED" />      <action android:name="android.bluetooth.intent.action.SCAN_MODE_CHANGED" />      <action android:name="android.bluetooth.intent.action.BLUETOOTH_STATE_CHANGED" />      <action android:name="android.bluetooth.intent.action.REMOTE_DEVICE_CONNECTED" />      <action android:name="android.bluetooth.intent.action.REMOTE_DEVICE_DISCONNECTED" />      <action android:name="android.bluetooth.intent.action.REMOTE_DEVICE_DISCONNECT_REQUESTED" />      <action android:name="android.bluetooth.intent.action.BOND_STATE_CHANGED" />      <action android:name="android.bluetooth.intent.action.PAIRING_REQUEST" />      <action android:name="android.bluetooth.intent.action.PAIRING_CANCEL" />      <action android:name="android.bluetooth.intent.action.REMOTE_DEVICE_CLASS_UPDATED" />      <action android:name="android.bluetooth.intent.action.REMOTE_DEVICE_FOUND" />      <action android:name="android.bluetooth.intent.action.REMOTE_NAME_UPDATED" />      <data android:scheme="file"/>       -->       <action android:name="android.bluetooth.intent.action.PAIRING_REQUEST" />    </intent-filter>  </receiver>
//本机显示pin      intent.action.PAIRING_REQUEST 本机不显示

<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />


4.使用串口通信,根据驱动程序,把蓝牙通信信息传输到串口。


然后和聂小猛童鞋程序类似。实现蓝牙通信。



原创粉丝点击