LocationListener 中的 onStatusChanged(String,int,Bundle) 已被弃用

Posted

技术标签:

【中文标题】LocationListener 中的 onStatusChanged(String,int,Bundle) 已被弃用【英文标题】:onStatusChanged(String,int,Bundle) in LocationListener has been deprecated 【发布时间】:2019-11-24 08:40:55 【问题描述】:

我在构建项目时有这个输出:

onStatusChanged(String,int,Bundle) in LocationListener has been deprecated

我发现我必须用public class LocationProvider 替换它。有谁知道我该如何解决?有什么想法吗?

【问题讨论】:

“这个回调永远不会被调用,并且提供者可以被视为始终处于 LocationProvider#AVAILABLE 状态。” 是的,但在 API 级别 29 中不再支持此状态。 这听起来像是警告,而不是错误。 正确。这是一个警告。但最好尽早找到解决方案,因为在未来的 api 版本中,可能会永久删除不推荐使用的方法。 【参考方案1】:

interface LocationListener的所有方法都必须被覆盖,但是警告可以忽略:

/**
 * Notice: This callback will never be invoked and providers can be
 * considered as always in the @link LocationProvider#AVAILABLE state.
 */
@Override @SuppressWarnings("deprecation")
public void onStatusChanged(String provider, int status, Bundle extras) 

【讨论】:

以上是关于LocationListener 中的 onStatusChanged(String,int,Bundle) 已被弃用的主要内容,如果未能解决你的问题,请参考以下文章

为啥我的 LocationListener 变为空?

Android 位置:PendingIntent 与 LocationListener

android:LocationListener 永久运行

locationListener + manager 与 GoogleServices + locationClient

LocationListener 没有提供任何速度更新

带有 locationListener 回调的 Android 服务