Android realizes the method of signal strength monitoring

  • 2020-06-07 05:16:37
  • OfStack

Monitoring of signal strength is one of the most common and important functions of Android. This paper presents an example of Android's approach to signal strength monitoring. Share to everybody for everybody reference.

The specific implementation code is as follows:


TelephonyManager Tel; 
MyPhoneStateListener MyListener; 

/* Update the listener, and start it */ 
MyListener = new MyPhoneStateListener(); 
Tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 
Tel.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); 

private class MyPhoneStateListener extends PhoneStateListener { 
/*  From the signal strength obtained , each tiome The supplier has updated  */ 
public void onSignalStrengthsChanged(SignalStrength signalStrength) { 
  super.onSignalStrengthsChanged(signalStrength); 
  Toast.makeText(getApplicationContext(),"Go to Firstdroid!!! GSM Cinr = "+ String.valueOf(signalStrength.getGsmSignalStrength()),Toast.LENGTH_SHORT).show(); 
  } 
}; 

Interested friends can test 1 under this article sample code, hope to be a definite help to your Android programming.


Related articles: