Why are constants in SignalStrength hidden?

Viewed 129

I use SignalStength to get the quality of the signal, before sending sms:

signalStrength.getLevel()

I then wanted to compare the integer with a static constant in SignalStength:

if (signalStrengthLevel == SignalStrength.SIGNAL_STRENGTH_POOR) {
    //...
}

But it doesn't compile in Android Studio. I realized that for some reason, these constants are marked as hidden in the source code:

/** @hide */
public static final int SIGNAL_STRENGTH_POOR
        = TelephonyProtoEnums.SIGNAL_STRENGTH_POOR; // = 1

Which forces me to copy/paste these constants in one of my own classes...

I then wonder if anyone knows the reason why the developers decided to mark these constants as hidden?

2 Answers

In the documentation of the TelephonyManager, we can find getSignalStrength() method, which returns SignalStrength type, which has getLevel() method. In the documentation of getLevel() method, we can read the following information about returned integer value:

a single integer from 0 to 4 representing the general signal quality. This may take into account many different radio technology inputs. 0 represents very poor signal strength while 4 represents a very strong signal strength.

Taking that into consideration, I'd solve that in the following way: create static values like:

private final static int VERY_POOR_SIGNAL = 0;
private final static int POOR_SIGNAL = 1;
private final static int MEDIUM_SIGNAL = 2;
private final static int STRONG_SIGNAL = 3;
private final static int VERY_STRONG_SIGNAL = 4;

and use this values to compare them with the integer value returned by:

telephonyManager.getSignalStrength().getLevel()

The word /** @hide */ just informs that the API is not accessible from SDK. I think it might be for security reasons.

Check this post

Related