检测正在插入的设备
我希望能够检测设备是否已插入。我希望能够像查询连接状态一样进行查询。这可能吗?或者我是否需要创建一个监听电池事件的广播接收器?
I would like to be able to detect whether or not the device is plugged in. I would like to be able to just query that the same way we can do for the connectivity state. Is that possible or do I need to create a broadcast receiver that listens for the battery events?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然 ACTION_BATTERY_CHANGED 是一个“粘性广播”,这意味着您可以注册并在广播后随时接收。要获得插入状态,您可以执行以下操作:
Apparently the ACTION_BATTERY_CHANGED is a "sticky broadcast" which means you can register for it and receive it any time after it has been broadcast. To get the plugged state you can do something like: