Polymerjs platinum-bluetooth元素用于与附近的蓝牙设备进行交互。
运行以下命令以在应用程序中使用platinum-bluetooth并将其安装在目录中。
bower install --save PolymerElements/platinum-bluetooth
文章图片
例子 它将在bower_components文件夹下安装所有platinum-bluetooth的相关元素。
创建一个index.html文件, 并在其中添加以下代码, 以查看Polymer.js中Platinum-bluetooth元素的用法。
<
!doctype html>
<
html>
<
head>
<
title>
Polymer Example<
/title>
<
script src = "http://www.srcmini.com/bower_components/webcomponentsjs/webcomponents-lite.js">
<
/script>
<
link rel = "import" href = "http://www.srcmini.com/bower_components/polymer/polymer.html">
<
link rel = "import" href = "http://www.srcmini.com/bower_components/paper-styles/demo-pages.html">
<
link rel = "import" href = "http://www.srcmini.com/bower_components/paper-button/paper-button.html">
<
link rel = "import" href = "http://www.srcmini.com/bower_components/platinum-bluetooth/platinum-bluetooth-device.html">
<
/head>
<
body>
<
section>
<
paper-button raised>
Get bluetooth device<
/paper-button>
<
/section>
<
script src = "http://www.srcmini.com/platinum_bluetooth.js">
<
/script>
<
/body>
<
/html>
现在, 创建另一个名为Platinum_bluetooth.js的文件, 并包含以下代码:
document.addEventListener('WebComponentsReady', function() {
var mybatteryDevice = document.querySelector('platinum-bluetooth-device');
var mybutton = document.querySelector('paper-button');
mybutton.addEventListener('click', function() {
console.log('The requested bluetooth device advertising a battery service...');
mybatteryDevice.request().then(function(device) {
console.log('Bluetooth device has been found...');
console.log('The device name is: ' + device.name);
})
.catch(function(error) {
console.error('Sorry!No device found...', error);
});
});
});
【Polymerjs platinum-bluetooth元素】输出
文章图片
推荐阅读
- Polymerjs platinum推送消息
- 通达2017OA办公系统-热销-全功能无限制源码CRM HR微信钉钉APP
- Android逆向基础
- 阶段3 2.Spring_03.Spring的 IOC 和 DI_5 BeanFactory和ApplicationContext的区别
- 关于获得安卓外部存储读写权限
- Xamarin Android 监听音量键(下)
- 彻底解析Android缓存机制——LruCache
- Android数据库使用指南(下)
- android SDK 安装