C# PC 通过bluetooth 连接手机1
2015-08-05 16:37
471 查看
<span style="white-space:pre"> </span>//这个里面博客里面的资料比较全http://hzy3774.iteye.com/blog/1735163 BluetoothClient Blueclient = new BluetoothClient(); Dictionary<string, BluetoothAddress> deviceAddresses = new Dictionary<string, BluetoothAddress>(); private void button1_Click(object sender, EventArgs e) { try { string temp = listBox1.SelectedItem.ToString(); BluetoothAddress DeviceAddress = deviceAddresses[temp]; Blueclient.SetPin(DeviceAddress,"0000"); Blueclient.Connect(DeviceAddress, BluetoothService.Handsfree); //if connect to Hands free. //client.Connect(deviceAddress, BluetoothService.SerialPort); //if connect to cell phone and so forth. if (Blueclient.Connected) { MessageBox.Show("Connect Successful."); } else { MessageBox.Show("Connect Failed."); } //transfer data..... } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void ScanAdd() { BluetoothRadio BuleRadio = BluetoothRadio.PrimaryRadio; BuleRadio.Mode = RadioMode.Connectable; BluetoothDeviceInfo[] Devices = Blueclient.DiscoverDevices(); deviceAddresses.Clear(); listBox1.Items.Clear(); foreach (BluetoothDeviceInfo device in Devices) { listBox1.Items.Add(device.DeviceName); deviceAddresses[device.DeviceName] = device.DeviceAddress; } } private void button2_Click(object sender, EventArgs e) { ScanAdd(); }
相关文章推荐
- Rabin_Karp(hash) HDOJ 1711 Number Sequence
- GUI编程:菜单的操作
- lingo中对start(@wrap(J+I+2,7))) >= required(J))的理解
- ios错误ignoring file xxx missing required architecture x86_64 in file
- getRequestDispatcher()和sendRedirect()的区别
- Android/Java 中的 String, StringBuffer, StringBuilder的区别和使用
- easyUI datagrid最后操作列的实现总结
- 视图UIView的frame、bounds与center属性
- CodeForces 5C Longest Regular Bracket Sequence
- Rescue(BFS) HDU 1242
- Leetcode 187 Repeated DNA Sequences 重复出现的DNA序列
- iOS培训-UI用户界面基础-tableView相关操作
- UIScrollView实现循环滚动和自动滚动
- NGUI 对话系统
- Activiti5 待审 待批任务 TaskQuery查询 条件查询 like查询
- iOS培训-UI用户界面基础-界面推送
- quick3.3与quick2.2的区别(3)
- UIScreen(屏幕)、UIWindow(画框)、UIView(画布)、didFinishLaunchingWithOptions、UIViewController各个方法的加载顺序
- UITableViewCell awakeFromNib
- Gradle finished with non-zero exit value 1 ic_launcher.png: Original is here. The version qualifie