Currently I'm writing a Service which has to take the Signal Strength of user's mobile set.
For this matter, I've implemented an inner class for the Service (lets say myPhoneStateListener) which extends the PhoneStateListener, and by overriding onSignalStrengthsChanged method I can successfully read the Signal Strength values ( from getGsmSignalStrength() method ).
Note that the TelephonyManager instance and listener got initialized in Service OnCreate method.
The issue is that I don't like to get the first value I get in onSignalStrengthsChanged body as Signal Strength value.
What I'd like to achieve is to somehow wait on PhoneStateListener and make sure that the listener has generated at least 10 samples and then save the last Signal Strength as the valid value.
Please be noted that currently I'm reading the values in Service onStartCommand method.
For doing that, I've tried to define a local variable (as counter) in Service class, It'll incremented by 1 each time when onSignalStrengthsChanged is called. in other hand in onStartCommand I'll wait and check if the variable reach to 10:
while ( m_nSignalStrength_Count < 10 )
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
But as I checked in debugging-mode, the variable doesn't change at all.