未找到Android国家/地区检测程序

时间:2016-06-28 08:10:50

标签: android android-studio

我想使用Country Detector,我可以在android sdk-23位置文件夹中看到。

enter image description here

但即使我导入整个位置包,也找不到这个类。

enter image description here

我甚至将min sdk支持仅保留为23。

enter image description here

我缺少什么?非常感谢提前!

2 个答案:

答案 0 :(得分:2)

CountryDetector可能位于源代码中,但它未包含在官方API中 - 而API是您的项目用作主库的库。 因此,您无法直接访问此类。

在这种特殊情况下,CountryDetector是一个系统服务,您可以通过Context.getSystemService申请(参见answer from Shanmugapriya D)。

在其他情况下,以下情况适用:

如果你想使用这个非官方类,你必须通过Java反射使用它。

例如,请参见此处: Android and reflection

或者,您可以尝试构建一个JAR文件,并将其作为provided添加到Gradle中。

答案 1 :(得分:2)

您不直接实例化此类;相反,检索它  * {@link android.content.Context#getSystemService  * Context.getSystemService(Context.COUNTRY_DETECTOR)}。 有关更多参考,您可以打开该java文件并检查