【问题标题】:onStatusChanged(String,int,Bundle) in LocationListener has been deprecatedLocationListener 中的 onStatusChanged(String,int,Bundle) 已被弃用
【发布时间】:2023-03-16 19:05:02
【问题描述】:

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

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

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

【问题讨论】:

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

标签: java android android-location


【解决方案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) {}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-21
    • 2023-03-25
    • 1970-01-01
    • 2022-10-21
    • 1970-01-01
    • 1970-01-01
    • 2015-02-03
    • 1970-01-01
    相关资源
    最近更新 更多