本例子演示了:

  • 判断蓝牙是否打开,是通过一个HRsult值为0x8007048F的异常来判断的

catch (Exception ex)
{
if ((uint)ex.HResult == 0x8007048F)
{
var result = MessageBox.Show(AppResources.Msg_BluetoothOff, "Bluetooth Off", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
ShowBluetoothcControlPanel();
}
}
  • 找到所有配对设备 - Windows.Networking.Proximity.PeerFinder

                PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
var peers = await PeerFinder.FindAllPeersAsync();
  • 尝试连接已配对设备

//从数据中获取已经选中的蓝牙设备,在ConnectToDevice方法中连接

            PairedDeviceInfo pdi = PairedDevicesList.SelectedItem as PairedDeviceInfo;
PeerInformation peer = pdi.PeerInfo; // Asynchronous call to connect to the device
ConnectToDevice(peer);

ConnectToDevice:

Windows.Networking.Sockets;

            try
{
Windows.Networking.Sockets.StreamSocket _socket = new StreamSocket();
string serviceName = (String.IsNullOrWhiteSpace(peer.ServiceName)) ? tbServiceName.Text : peer.ServiceName; // Note: If either parameter is null or empty, the call will throw an exception
await _socket.ConnectAsync(peer.HostName, serviceName); // If the connection was successful, the RemoteAddress field will be populated
MessageBox.Show(String.Format(AppResources.Msg_ConnectedTo, _socket.Information.RemoteAddress.DisplayName));
}
  • 当捕获蓝牙未打开的异常,后打开蓝牙设置页面:(Microsoft.Phone.Tasks)
        private void ShowBluetoothcControlPanel()
{
ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.Bluetooth;
connectionSettingsTask.Show();
}

例子:Bluetooth app to device sample的更多相关文章

  1. 例子:Background Audio Streamer Sample

    The Background Audio Streamer sample demonstrates how to create an app that uses a MediaStreamSource ...

  2. 例子:Background Transfer Service Sample

    本例演示了如何使用后台传输服务来进行后台文件下载,也就是说及时App已经停止运行,同样可以通过后台代理进行文件的下载操作. 对于后台文件传输一下知识点必须注意: 1. 通过使用 BackgroundT ...

  3. 例子:Camera Color Picker Sample (YCbCr->ARGB)

    本例演示了如何从相机preview缓冲区获取YCbCr模块,并且转化为ARGB. 1. 什么是YCbCr y:像素的亮度.以范围从 0 到 255 的字节值形式返回(亮度值始终为正值). cr:像素的 ...

  4. Android Bluetooth开发

    原文地址:http://developer.android.com/guide/topics/wireless/bluetooth.html 翻译:jykenan 更新:2012.06.19 Andr ...

  5. windows 10 开发学习资料,Windows-universal-samples学习笔记系列一:App settings

    windows 10 通用代码范例: https://github.com/Microsoft/Windows-universal-samples 相关视频:https://mix.office.co ...

  6. bluetooth在linux应用开发

    linux内Bluetooth的协议栈为BlueZ,http://www.bluez.org/.在4.46上,BlueZ实现了对A2DP Sink的支持,而之前的版本只支持A2DP Source.

  7. 蓝牙App漏洞系列分析之二CVE-2017-0639

    蓝牙App漏洞系列分析之二CVE-2017-0639 0x01 漏洞简介 Android本月的安全公告,修复了我们发现的另一个蓝牙App信息泄露漏洞,该漏洞允许攻击者获取 bluetooth用户所拥有 ...

  8. 6个错误将杀死你的App

    没有开发者或者设计师会故意破坏应用的设计.所有的应用程序创建者都对自己的应用寄予美好的愿望,但是很多错误是在他们无意识的状态下破坏app的设计.以下是应用开发者和设计者经常犯的几个错误,不过这些错误是 ...

  9. 执行umount 命令的时候出现 device is busy

    执行umount 命令的时候出现 device is busy ,有人在使用这块磁盘 umount /dev/sde1 umount: /u01/app/oracle: device is busy ...

随机推荐

  1. ListView下拉加载一(分页)

    首先创建在主xml里放置一个listview列表,代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/r ...

  2. mysql事务处理

    事务处理能保证所有的sql操作一次性完成或回滚,mysql默认的MyISAM表类型是不支持事务处理的,如果需要做事务处理,需要把表类型换成InnoDB <?php $dsn='mysql:hos ...

  3. js 作用域

    js 作用域 js作用域链查找,子函数能取到父函数中定义的变量. 前段时间误写成如下形式: 这只是普通的函数调用,没有父子的关系,child()函数会在全局查找pi变量,没找到所以报错. 最近发现原来 ...

  4. typeof,GetType

    typeof: 是运算符,获得某一类型的 System.Type 对象. Int32 t = new Int32(); Type t = typeof(int); GetType: 是方法,获取当前实 ...

  5. SQL与Mongodb聚合的对应关系(举例说明)

    SQL中的聚合函数和Mongodb中的管道相互对应的关系: WHERE $match GROUP BY $group HAVING $match SELECT $project ORDER BY $s ...

  6. iOS —— 字典遍历排序

    字典NSDictionary一般的遍历方法都是: NSArray* arr = [yourdictonary allKeys]; for(NSString* str in arr) { NSLog(& ...

  7. mybatis if判断中的特殊符号

    在使用mybatis 时我们sql是写在xml 映射文件中,如果写的sql中有一些特殊的字符的话,在解析xml文件的时候会被转义,但我们不希望他被转义,所以我们要使用<![CDATA[ ]]&g ...

  8. dos命名重启或关闭远程服务器

    1.建议远程连接.(把远程机器IP换成实际IP地址,把密码改为administrator的真实密码) net use \\远程机器IP\ipc$ "密码"/user:adminis ...

  9. 补PSP进度(10.28-11.3)

    本周PSP进度 10月31号 内容 开始时间 结束时间 打断时间 净时间 看蛋白质相互作用论文 8:40 10:35 约12m 103m 分析约跑功能 13:20 13:55 0 35m 练习VSL2 ...

  10. ThinkPHP 3.2.3(一)基础

    一.安装 ThinkPHP无需任何安装,直接拷贝到你的电脑或者服务器的WEB运行目录下面即可. 如:我使用的是XAMPP集成环境,将框架解压缩到htdocs目录下即可.   二.目录结构 1.初始目录 ...