本例子演示了:

  • 判断蓝牙是否打开,是通过一个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. 实验一 认识DOS

    #include<stdio.h> #include<string.h> void main() {       char cmd[20][20]={"dir&quo ...

  2. 别不信!App三年内将被HTML5顶替彻底消失?

    2007年W3C(万维网联盟)立项HTML5,直至2014年10月底,这个长达八年的规范终于正式封稿. 过去这些年,HTML5颠覆了PC互联网的格局,优化了移动互联网的体验,接下来,HTML5将颠覆原 ...

  3. PHP data

  4. OnTimer

    OnTimer不是多线程. OnTimer是以SendMessage的方式发送消息到消息队列. sendMessage必须等待对话框响应完消息后才返回.

  5. selenium ide脚本回放出现element not found

    原因: 点击按钮,没有设置时间延迟,而页面加载,需要时间:当页面元素未加载完全,执行点击事件,就会报错:element... not found. 解决方案: 在点击事件前添加新的COMMAND.设置 ...

  6. O2O、C2C、B2B、B2C的区别

    一.O2O.C2C.B2B.B2C的区别在哪里? o2o 是 online to offline 分为四种运营模式 1.online to offline 是线上交易到线下消费体验 2.offline ...

  7. js数据类型

    JavaScript数据类型是非常简洁的,它只定义了6中基本数据类型 null:空.无.表示不存在,当为对象的属性赋值为null,表示删除该属性 undefined:未定义.当声明变量却没有赋值时会显 ...

  8. 关于android的@TargetApi和@SuppressLint("NewApi")

    看别人的代码好多地方用到了@TargetApi.以前一直不知道这个是什么意思.后面偶然看了下sdk.才有所明白. 其实这个东西就是在你使用了android Lint检查工具的时候,为了防止代码出现提示 ...

  9. Redis常用命令入门5:有序集合类型

    有序集合类型 上节我们一起学习了集合类型,感受到了redis的强大.现在我们接着学Redis的最后一个类型——有序集合类型. 有序集合类型,大家从名字上应该就可以知道,实际上就是在集合类型上加了个有序 ...

  10. META-INF文件夹是干啥的,META-INF文件夹的作用, META-INF文件夹能删吗

    今天有人问到 META-INF文件夹是干啥的,META-INF文件夹的作用, META-INF文件夹能删吗,还有项目的META-INF下面一般会有个MANIFEST.MF 文件,都是干啥的. 百度搜了 ...