Android phones get signal strength information
This document describes how to use the Android system to get mobile phone signal strength and other information
- Android phones get signal strength information
-
- Background introduction
- Related research
- Find source
- Code implementation
- Summarize
Background introduction
The company's theme business is the development of the communication base station, I need to develop a software to match the base station test work. After connecting to the base station via the Android phone, collect various information about the signal strength on the phone, then analyze the data and complete the test of the base station by analyzing the data.
Related research
The parameters to be tested are mainly:
-rsrp
-rssi
-rsrq
-snr
-signal Strength
Here, I do not explain these parameters, there is a need for self-Baidu.
Find source
Because Android applications on the market are rarely tested for signal strength, we go directly to the SDK provided by Google to find out how we can achieve our needs.
We found the Signalstrength class in the SDK, with information about the signal strength in the Signalstrength class, and I took the details of the class:
However, we still do not see RSSI, RSRP, RSRQ and other information. I've looked through all the classes that might be related to signal strength, but I can't find them, so I went to the source code for the Signalstrength class. By looking up the source code, I found the secret inside. (my most commonly used to view the Android source of the site is grepcode.com, the source code is listed according to the Android version, very good)
I put on the Signalstrength.java first, and then explain the mystery inside.
Here is the parameter diagram for the class:
We were surprised to find that we had the variables we needed, and found that we were going to find the corresponding get function and find
In fact, in the Signalstrength class, there is a way to get these parameters, but for some reason Google has hidden them up. So how do we get these values?
is to use the ToString () method:
Although the Signalstrength class does not provide us with an interface for getting information, we can parse the arguments by using the ToString method.
Code implementation
We know that using the ToString method of the Signalstrength class can take out the parameters we need, so how do we use the Signalstrength class? I posted my code for reference:
TelephonyManager tm =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); new PhoneStateListener() { publicvoidonSignalStrengthsChanged(SignalStrength signalStrength) { String singalInformation = signalStrength.toString(); } }; tm.listen(MyPhoneListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
Where we get the singalinformation variable is a string containing the signal information, and we can parse it ourselves to get the parameters we need.
Summarize
This article is mainly about how to get the power of Android phone and cell phone signal, we get the strength of these signals by looking up the source code of Android.
Android phones get signal strength information