Javascript 如何在chrome应用程序开发中列举已连接的USB和Wi-Fi设备
样本代码随附 manifest.jsonJavascript 如何在chrome应用程序开发中列举已连接的USB和Wi-Fi设备,javascript,html,google-chrome-app,Javascript,Html,Google Chrome App,样本代码随附 manifest.json { "manifest_version": 2, "name": "Devices", "version": "0.1", "minimum_chrome_version": "26", "app": { "background": { "scripts": ["background.js"] } }, "permissions": [ "usb", {"usbDevices": [
{
"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>
我正在尝试将连接的设备显示到应用程序窗口。因为我是这方面的新手,所以没有成功
请提前感谢,Sarath s我相信你的两项任务都是不可能完成的(不管怎样,如果没有a)
chrome.system.network
API枚举网络接口,但网络上任何类型的设备发现都将高度依赖于您的意思
您无法枚举WiFi网络,您必须实现自己的特定服务发现(只要可以使用chrome.socket.tcp
/chrome.socket.udp
)
您包含的代码有点无用:它是一个框架,没有与当前问题相关的功能,因此基本上您没有尝试解决它。
function GetUsbDevices()
{
//alert('Clicked USB Device Button');
console.log("Device could not be found");
}