2

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?

user2923322
  • 1,072
  • 1
  • 11
  • 25
  • 1
    I doubt you're going to get a definitive answer unless, for some reason, one of the developers at Google that were involved in writing/reviewing that particular piece of code decides to come here and anwer your question. I would say, if something is marked `@hide`, it's typically to discourage app developers from making use of those symbols. There could be various reasons for wanting to discourage that. Perhaps you have a set of constants that isn't stable and could change from one Android version to another. – Michael Nov 07 '18 at 10:52

2 Answers2

0

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()
Piotr Wittchen
  • 3,853
  • 4
  • 26
  • 39
  • 2
    Yes I wrote "Which forces me to copy/paste these constants in one of my own classes...". Ofc I can just copy/paste these constants in one of my classes, just as you suggested as well. But the question really is: why did they decide to mark these constants as hidden in SIgnalStrength – user2923322 Nov 07 '18 at 10:33
  • that is basically what user2923322 did : `Which forces me to copy/paste these constants in one of my own classes...`, and he is asking `Why are constants in SignalStrength hidden?`, therefore your answer does not answer the question. – Vladyslav Matviienko Nov 07 '18 at 10:33
  • Ok, I don't know why these constants are hidden. I just provided the feasible solution to deal with this issue. Maybe developers of Android Framework had some reason to do that related to their internal development process. I think, in this case due to lack of documentation ,only Android Platform Developers could answer that question... – Piotr Wittchen Nov 07 '18 at 10:49
0

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

Check this post

Gratien Asimbahwe
  • 1,606
  • 4
  • 19
  • 30