即时信号强度
我需要找到一种方法来测量Android手机当前的信号强度,而不需要注册一个PhoneStateListener,上帝知道它何时返回实际的asu。
比如:
int signal = getPhoneSignal();
请问有什么帮助吗?
谢谢!
I need to find a way to measure the current signal strength of Android phone, without the need to register a PhoneStateListener that God knows when it returns the actual asu.
something like:
int signal = getPhoneSignal();
any help plz?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您仔细查看 Android 源代码,您会发现注册
PhoneStateListener
后您将收到即时通知:因此您可以创建自己的计时器并在计时器更新时注册新侦听器,并在接收即时更新后删除它通过传递相同的侦听器对象并将事件参数设置为 LISTEN_NONE 来实现。
当然,我不能称其为最佳实践,但我能看到的唯一替代方案是根据
getNeighboringCellInfo()
的信号强度自行计算信号强度。ps 不仅是上帝知道何时触发
PhoneStateListener
;)If you will have a closer look on Android sources you will see that after registering
PhoneStateListener
you will have instant notification:So you can create your own timer and on timer update register new listener and after receiving instant update remove it by passing the same listener object and set the events argument to
LISTEN_NONE
.Of course I can't call it best practice but the only alternative I can see is to calculate signal strength by yourself based on signal strengths from
getNeighboringCellInfo()
.p.s. Not only God knows when
PhoneStateListener
will be triggered ;)我认为没有办法直接做到这一点。但是您可以注册 PhoneStateListener 并将最后更新的值保存到变量中并返回/调用它。
I don't think there is a way to do it directly. But you could register the PhoneStateListener and save the last updated value into a variable and return/call this.
其中:
这是工作代码。不要忘记在清单中注册您的服务并获取权限。可能有更好/更优雅的方法来做到这一点,所以欢迎评论/更正。
where :
This is working code. Do not forget to register your services in the manifest and acquire permissions. There may be better/ more elegant ways of doing this so comments/corrections welcome.