且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获得手机服务信号强度的Andr​​oid?

更新时间:2023-02-26 21:39:37

创建一个PhoneStateListener并处理onSignalStrengthChanged回调。当你的应用程序初始化,它应该给你一个初始通知。这是在1.x的在2.x中,有一个开放的问题这一点。

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);

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.