如何在Android中获取手机服务信号强度?
我正在尝试编写一个非常简单的 Android 应用程序来检查当前小区的信号强度。到目前为止,我只找到了一个名为 getNeighboringCellInfo()
的东西,但我不确定它是否包含当前单元格。
如何在 Android 中获取当前的手机信号强度?
getNeighborCellInfo()
是否获取当前单元格?根据我所能得到的结果,这似乎并非如此。这是我当前的代码:
List<NeighboringCellInfo> n = tm.getNeighboringCellInfo();
//Construct the string
String s = "";
int rss = 0;
int cid = 0;
for (NeighboringCellInfo nci : n)
{
cid = nci.getCid();
rss = -113 + 2*nci.getRssi();
s += "Cell ID: " + Integer.toString(cid) + " Signal Power (dBm): " +
Integer.toString(rss) + "\n";
}
mainText.setText(s);
I am trying to write a very simple Android application that checks the signal strength of the current cell. So far, I have only found something called getNeighboringCellInfo()
, but I'm not really sure if that includes the current cell.
How do I get the CURRENT cell signal strength in Android?
Does getNeighborCellInfo()
get the current cell? It doesn't seem like it based on the results that I have been able to get with it. Here's my current code:
List<NeighboringCellInfo> n = tm.getNeighboringCellInfo();
//Construct the string
String s = "";
int rss = 0;
int cid = 0;
for (NeighboringCellInfo nci : n)
{
cid = nci.getCid();
rss = -113 + 2*nci.getRssi();
s += "Cell ID: " + Integer.toString(cid) + " Signal Power (dBm): " +
Integer.toString(rss) + "\n";
}
mainText.setText(s);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建一个 PhoneStateListener 并处理 onSignalStrengthChanged 回调。当您的应用程序初始化时,它应该给您一个初始通知。这是 1.x 中的。在 2.x 中,存在一个关于此的开放问题。
create a PhoneStateListener and handle the onSignalStrengthChanged callback. When your app is initialized, it should give you an initial notification. This is in 1.x. in 2.x, there's an open issue about this.
此代码可能会有所帮助:
创建自己的电话状态侦听器后,使用位掩码将其注册到电话管理器以指示要侦听的事件,如以下代码片段所示:
此外,需要将这些添加到AndroidManifest.xml:
This code may help:
Once you’ve created your own Phone State Listener, register it with the Telephony Manager using a bitmask to indicate the events you want to listen for, as shown in the following code snippet:
Also, need to add these to AndroidManifest.xml:
下面的代码将创建类似图片的效果(Android系统单元格信息)
在您正在运行的活动/片段中,创建一个像这样的子类
在其他地方调用,可能是onCreate或在按钮之后...(使用线程来不断更新值改变)
Below code will create effect like picture (Android system Cell Info)
Inside your running activity/fragment, create a sub class like this
Call somewhere else maybe onCreate or after a button... (used thread to update continnously value changed)