如何定义chrome.bluetooth成功?

How to define chrome.bluetooth successfully?

我正在为 chrome 寻找蓝牙低功耗对象的最小工作示例,这样:

chrome.bluetooth

returns

以外的东西
undefined

在运行时从 javascript。

我尝试了 manifest.json 的各种形式,包括:

{
  "name": "Bluetooth Low Energy Test App",
  "description": "App testing the chrome.bluetoothLowEnergy API",
  "version": "0.1",
  "app": {
    "background": {
      "scripts": ["background.js"]
    }
  },
  "bluetooth": {
    "low_energy": true
  }
}

{
  "name": "Bluetooth Low Energy Test App",
  "description": "App testing the chrome.bluetoothLowEnergy API",
  "version": "0.1",
  "app": {
    "background": {
      "scripts": ["background.js"]
    }
  },
  "bluetooth": {}
}

{
    "name": "Bluetooth Low Energy Test App",
    "description": "App testing the chrome.bluetoothLowEnergy API",
    "version": "0.1",
    "app": {
        "background": {
            "scripts": ["background.js"]
        }
    },
    "bluetooth": {
        "profiles": [
            "00001101-0000-1000-8000-00805f9b34fb" // array of uuids
        ]
    }
}

但是其中的 none 在 javascript 控制台中产生了一个有效的 chrome.bluetooth 实例。

我已经在 Chrome 42 和 44 上测试过 Mac OS X 和 ChromeOS 并启用了蓝牙。两台机器都打开了蓝牙,可以看到 BTLE 设备。

chrome.bluetooth 是否适用于任何平台上的任何版本的 Chrome?

我从没用过这个 api 但看看 developer.chrome.com/apps/manifest/bluetooth

还有developer.chrome.com/apps/bluetoothLowEnergydeveloper.chrome.com/apps/bluetoothSocket因为 Chrome 37.

这是(我想你在找什么)一个更好的例子和如何使用它的解释(获取设备、发现设备等的例子)Good stuff

另一个示例应用程序:

github.com/armansito/ble-battery-service-demo/blob/master/script.js github.com/GoogleChrome/chrome-app-samples/tree/master/samples/bluetooth-samples/device-info-demo

抱歉纯文本链接,粘贴超过 2 个没有声誉...

缺少的 link 是 manifest.json 描述的 HTML 和 JavaScript 必须安装为 chrome 扩展。实现此目的的最简单方法是从 github 下载应用程序的 zip,将其解压缩到下载,然后:

  1. 点击menu/moretools/extensions
  2. 点击开发者模式复选框
  3. 点击加载解压扩展
  4. selectHTML/CSS/JSON
  5. 的解压文件夹
  6. 转到开发者工具
  7. 检查 chrome.bluetooth 实例
  8. 检查 chrome.bluetoothLowEnergy 实例

在我的 chrome 书中,无论我使用哪个 chrome 版本,所有这些都已定义。

我是 运行 宏碁 C720P。

chrome 扩展名是我缺少的 link。我应该从 manifest.json.

知道的

我正在考虑向 chrome.bluetooth 和 chrome.bluetoothLowEnergy 的文档发出拉取请求以提及扩展要求,因为这对我来说并不明显,但我认为这源于给定本地文件系统与远程 URI 所需的沙箱。考虑到 GPS 芯片组等的行为,您没有收到有关蓝牙访问的提示确实有点奇怪。