开发者

Android - is SignalStrength an Event Class?

开发者 https://www.devze.com 2023-04-04 20:29 出处:网络
I have a little problem with a SignalStrength Android class. Is there a way to use methods from this class without referencing an object from this class in a onSignalStrengthsChanged() method?

I have a little problem with a SignalStrength Android class. Is there a way to use methods from this class without referencing an object from this class in a onSignalStrengthsChanged() method? From all the examples I saw, it seems to me that this is an Event Class and that object is created when an event (change of gsm signal strength) occurs and that this is the only way to call methods from this class. Am I right?

    public void onSignalStrengthsChanged(SignalStrength signalStrength)
  {
     String power= S开发者_JS百科tring.valueOf(signalStrength.getGsmSignalStrength());
     gsmStat.setText("GSM cinr: " +power);
  }

What if I want to call methods from this class (and read gsm signal properties) in some other case, for example when I click a button object?

Thank you very much for any help, I'm really stuck with this.

BR, Z


Thank you for clearing this up. I tried to use getNeighbouringCellInfo but for some reason this return 0. And yes I've searched and tried different examples.

Tel = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);

public void onClick(View v) {
List<NeighboringCellInfo>  neighCell = null; 
neighCell = Tel.getNeighboringCellInfo(); 
NeighboringCellInfo thisCell = neighCell.get(1);
int thisNeighRSSI = thisCell.getRssi();
String rssi=Integer.toString(thisNeighRSSI);
tvRSSI.setText("Test: " +rssi);
 }


You can't. The only way to get a relevant SignalStrength object is in the onSignalStrengthChanged method.

You can, however, use the TelephonyManager.getNeighbouringCellInfo method to list surrounding cells and get the signal RSSI power (getRssi).


See: getNeighboringCellInfo() returning null list

getNeighboringCellInfo()

This doesn't seem to work on Samsung devices.

Sorry to put this as an answer, but I cannot add a comment to an existing answer.

As for my answer, you can track the RSSI yourself in a service so that when you press the button, the last recorded RSSI value is returned. Having said that, I've found that on the Samsung Galaxy I work with, the RSSI value is actually the number of antenna bars (ie. I only get 4 values) and not the actual RSSI.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号