没有构造函数时如何扩展 CellSignalStrength class?

How to extend the CellSignalStrength class when it doesn't have a constructor?

有一个名为 <a href="http://developer.android.com/reference/android/telephony/CellSignalStrength.html" rel="nofollow noreferrer">CellSignalStrength</a> 的 class 没有默认构造函数。

为了能够使用 SignalStrength,我必须制作一个 class 来提取它,但我做不到,因为当我尝试这样做时,它会打印出错误:

No default contstructor available for SignalStrength.

此外,还有另一个 class 称为 <a href="http://developer.android.com/reference/android/telephony/CellSignalStrengthGsm.html" rel="nofollow noreferrer">CellSignalStrengthGsm</a>(同样的问题),但是 class 扩展了 SignalStrength class,但是如何呢?


我对此做了一些研究,但我找不到任何东西,但是 this guide 只向我提供邻近小区站点的信号强度,其中 none给我提供信号的那个。该解决方案没有提供实际信号强度。

为什么 Android 文档没有至少一个如何使用 class 的示例?

我真的需要帮助,我被卡住了:/

我能想到你不能扩展 CellSignalStrength class 的唯一原因是因为它的构造函数是 <a href="https://searchcode.com/codesearch/view/25270611/" rel="nofollow">protected CellSignalStrength()</a>。意味着只有同一包中的其他 classes 可以扩展它。

Android 开发人员可能有充分的理由这样做。我的建议是重新考虑您要尝试做的事情并找出另一种解决方案。也许使用 classes 之一的实例 sub-classes CellSignalStrength:

Note: These classes are all final, so don't try to extend them.

CellSignalStrengthCdma
CellSignalStrengthGsm
CellSignalStrengthLte
CellSignalStrengthWcdma