【问题标题】:how to enumerate connected USB and Wi-Fi devices in chrome app development如何在 Chrome 应用程序开发中枚举连接的 USB 和 Wi-Fi 设备
【发布时间】:2014-06-13 11:26:54
【问题描述】:

附上示例代码

manifest.json

 {
  "manifest_version": 2,
  "name": "Devices",
  "version": "0.1",
  "minimum_chrome_version": "26",
  "app": {
    "background": {
      "scripts": ["background.js"]
    }
  },
 "permissions": [
 "usb",
    {"usbDevices": [
      {
        "vendorId": 1234,
        "productId": 145
      }
    ]}
  ]
}

background.js

chrome.app.runtime.onLaunched.addListener(function(launchData) {
  chrome.app.window.create('index.html', {id:"fileWin", bounds: {width: 800, height: 500}}, function(win) {
    win.contentWindow.launchData = launchData;
  });
});

index.html

<html>
    <head>
        <title> Devices</title>

        <style>
            button {
                    display: inline-block;
                    background: -webkit-linear-gradient(#F9F9F9 40%, #E3E3E3 70%);
                    background: linear-gradient(#F9F9F9 40%, #E3E3E3 70%);
                    border: 1px solid #999;
                    -webkit-border-radius: 3px;
                    border-radius: 3px;
                    padding: 5px 8px;
                    outline: none;
                    white-space: nowrap;
                    -webkit-user-select: none;
                    user-select: none;
                    cursor: pointer;
                    text-shadow: 1px 1px #fff;
                    font-weight: 700;
                    font-size: 10pt;
                }
            button:not(:disabled):hover {
                    border-color: black;
                }
            button:not(:disabled):active {
                    background: -webkit-linear-gradient(#E3E3E3 40%, #F9F9F9 70%);
                    background: linear-gradient(#E3E3E3 40%, #F9F9F9 70%);
                }
        </style>    
    </head>
    <body>
        <p>Devices<br><br>
            <nav>
                    <button id="usb_dev" onclick="GetUsbDevices()">USB</button>
                    <button id="wifi_dev" ">Wi-Fi</button>
            </nav>
        </p
        <script src="script.js"></script>
    </body>
</html>

script.js

function GetUsbDevices() 
{
    //alert('Clicked USB Device Button');
   console.log("Device could not be found");

}

我正在尝试将连接的设备显示到应用程序窗口。因为我是这个开发的新手,但没有成功。

请帮助提前谢谢,Sarath s

【问题讨论】:

  • 你包含的代码有点没用:它是一个骨架,没有与手头问题相关的功能,所以基本上你没有尝试解决它。​​

标签: javascript html google-chrome-app


【解决方案1】:

我确实相信你的两个任务都无法完成(无论如何,如果没有 Native Host)。

  1. 出于安全目的明确禁止 USB 枚举,我概述了 here

    这样做的原因是通过枚举所有连接的 USB 设备来防止应用对硬件进行指纹识别,这很有可能成为唯一的集合。

  2. 不清楚您所说的“WiFi 设备”是什么意思;您可以使用chrome.system.network API 枚举网络接口,但网络上任何类型的设备发现都将高度依赖您的意思。

    您无法枚举 WiFi 网络,您必须实现自己的特定服务发现(只要可以使用 chrome.socket.tcp/chrome.socket.udp)。

【讨论】:

    猜你喜欢
    • 2011-07-11
    • 1970-01-01
    • 2017-09-14
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    相关资源
    最近更新 更多