Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

android - Instant signal strength

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you will have a closer look on Android sources you will see that after registering PhoneStateListener you will have instant notification:

public void listen(PhoneStateListener listener, int events) {
        String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>";
        try {
            Boolean notifyNow = (getITelephony() != null);
            mRegistry.listen(pkgForDebug, listener.callback, events, notifyNow);
        } catch (RemoteException ex) {
            // system process dead
        }
    }

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...