是否可以通过网络浏览器 api 访问移动设备的电池状态或充电? [英] Is it possible to access a mobile devices battery status or charge via a web browser api?

查看:23
本文介绍了是否可以通过网络浏览器 api 访问移动设备的电池状态或充电?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间环顾四周,看看是否可以通过网络浏览器 API 访问移动设备的电池状态或充电,但没有找到任何资源,甚至没有找到任何讨论这个主题的内容.这让我相信这是不可能的,因为无论出于何种原因(安全?),它都不在规范中.

I've spend some time looking around to see if it is possible to access a mobile devices battery status or charge via a web browser api but haven't found any resources or really anything even discussing this topic. This makes me believe it's not possible as it isn't in the spec of whatever reason (security?).

无论哪种方式,我都发现可以使用 iOS、Cordova、Phonegap、Appcelerator 等获取电池状态/充电百分比.所有这些都有一个 API,我可能可以开始工作我正在研究开发.然而,所有这些解决方案仍然需要应用程序作为本机应用程序运行 - 我希望能够在设备上的浏览器中运行它.

Either way I've found that it is possible to get the battery status / charge percentage with iOS, Cordova, Phonegap, Appcelerator etc.. all of which has an API I might be able to get to work might work for what I am looking into developing. However all of these solutions still would required the app to run as native app — I'm hoping to be able to run it in browser on the device.

这可能吗?如果是这样,我应该研究什么浏览器 API?

Is this possible? If so, what browser API should I be looking into?

推荐答案

感谢 Tapani 和 Michael,

Thanks Tapani and Michael,

您的帮助无疑为我指明了正确的方向.根据您提供的信息,我能够找到有关规范以及支持 API 的浏览器的更多信息.

Your help definitely pointed me in the right direction. With the info you provided I was able to find more info on the spec and what browsers support the api.

  • Chrome 42.0.2311.90(64 位)似乎不支持电池 API.
  • Chromium 版本 22.0.1225.0 (149762) 也不支持电池 API.
  • Chrome Canary 版本 44.0.2387.0 Canary(64 位)支持 MDN 规范(https://developer.mozilla.org/en-US/docs/Web/API/Battery_Status_API) 但不支持 navigator.battery 命名空间.
  • Firefox 支持 navigator.battery 命名空间,但不支持 navigator.getBattery() 函数.
  • Safari 8.0.5 版 (10600.5.17) 不支持任何涉及电池 API 的内容.
  • Chrome 42.0.2311.90 (64-bit) does not seem to support the battery API.
  • Chromium Version 22.0.1225.0 (149762) also does not support the battery API.
  • Chrome Canary Version 44.0.2387.0 canary (64-bit) supports the spec on MDN (https://developer.mozilla.org/en-US/docs/Web/API/Battery_Status_API) but does not support the navigator.battery namespace.
  • Firefox supports the navigator.battery namespace but does not support the navigator.getBattery() function.
  • Safari Version 8.0.5 (10600.5.17) doesn't support anything referring to the battery api that I can tell.

我没有在移动设备上检查这个,但我不怀疑移动浏览器会更一致的 api,甚至比上述任何浏览器都实现得更好.似乎相当新,浏览器组织仍在试图找出并努力遵循记录的规范.让我想起了一些 CSS flex-box.

I didn't get around to checking this on mobile but I don't suspect that mobile browsers would be more consistent api or even have it implemented better than any of the above browsers. Seems fairly new and the browsers organizations are still trying to figure out and are struggling to follow the documented spec. Reminds me a bit of CSS flex-box a bit.

谢谢各位!

这篇关于是否可以通过网络浏览器 api 访问移动设备的电池状态或充电?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆