CoverageInfo.getCoverageStatus() 与 CoverageInfo.isCoverageSufficient(),它们相同吗?
在尝试确定是否支持特定连接时,我对 CoverageInfo.getCoverageStatus() 和 CoverageInfo.isCoverageSufficient() 之间的差异感到困惑。例如:
// check mds with getCoverageStatus() and bitwise check
boolean hasMdsCoverage1 = (CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS;
// check mds with isCoverageSufficient()
boolean hasMdsCoverage2 = CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_MDS);
hasMdsCoverage1 和 hasMdsCoverage2 似乎返回相同的结果,但为什么有两种不同的方法呢?是否存在返回不同结果的情况?
理想情况下,我想使用 CoverageInfo.isCoverageSufficent(),因为这在代码中看起来更干净,但在这样做之前,我想确保我没有错过任何 getCoverageStatus( ) 会提供。
注意:我用它来检查通过 BIS、MDS、WAP 和 WAP2 协议的有效连接。
In trying to determing a if a specific connection is supported, I'm cofused about the difference between CoverageInfo.getCoverageStatus() and CoverageInfo.isCoverageSufficient(). For example:
// check mds with getCoverageStatus() and bitwise check
boolean hasMdsCoverage1 = (CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS;
// check mds with isCoverageSufficient()
boolean hasMdsCoverage2 = CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_MDS);
Both hasMdsCoverage1 and hasMdsCoverage2 seem to return the same result, but why two different approaches? Is there ever a case where they'll return a different result?
Ideally I'd like to use CoverageInfo.isCoverageSufficent() since this looks cleaner in code, but before I do so I want to make sure I'm not missing out on anything that getCoverageStatus() would provide.
NOTE: I'm using this to check for valid connections via BIS, MDS, WAP and WAP2 protocols.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
getCoverageStatus() 返回 COVERAGE_ 标志位掩码*,其中 isCoverageSufficient() 如果设备在某些可用路线上具有由coverageType 指定的覆盖类型,则返回布尔值 true;否则为假。当按照您的方式编码时,没有区别,但在 hasMdsCoverage1 中,您需要进行额外的处理,使它们等效。 isCoverageSufficient 在这种情况下可能更方便, getCoverageStatus 在其他情况下可能更方便。如果前者调用后者,我不会感到惊讶。许多不同的支持库中有许多这样的示例。
getCoverageStatus() returns A bitmask of COVERAGE_ flags*, where isCoverageSufficient() returns a boolean true if the device has the type of coverage specified by coverageType, over some available route; otherwise false. When coded the way you have there is no difference, but in hasMdsCoverage1 you have additional processing that makes them equivalent. isCoverageSufficient may be more convenient it this case, getCoverageStatus may be more convenient in others. I would not be surprised if the former calls the latter. There are many such examples in many different support libraries.