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

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

问题描述

我花了一些时间环顾四周,以查看是否可以通过Web浏览器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/zh-CN/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,甚至比任何上述浏览器都可以实现更好的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.

谢谢大家!

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

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