我有一个应用程序,我在其中的第一页获取当前位置。在印度应用程序运行良好并获取当前位置。当我们在美国运行应用程序时,应用程序在第一页本身崩溃并抛出 IllegalArgumentException。
最佳答案
手机没有启用任何提供商来检测位置,即它既没有连接到 GPS
也没有连接到 WI-FI
,在这种情况下,提供商正在作为 null 传递。这是假设您为 requestLocationUpdates()
函数提供 provider
参数,找到最佳提供者,如果找不到,它将返回 null。
在进一步处理此事之前,我会先检查是否启用了任何提供程序。为避免将 null 作为提供者传递,请在调用位置更新之前检查提供者是否为 null。
if (provider != null) {
requestLocationUpdates()
} else {
// alert user asking him to enable one of the providers.
}
这就是您的做法。
HTH.
关于android - 在 android 的 LocationManager 中显示 java.lang.illegalargumentexception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7512661/