地理围栏 - addOnCompleteListener(this) 不工作

Geofences - addOnCompleteListener(this) not working

我正在尝试构建一个地理围栏应用程序。我在 GitHub 上找到了一个示例,并在我的大部分项目中引用了它。如果它有任何意义,这段代码包含在示例中的 MainActivity 中,但我在另一个 activity.

中有它

在 addGeofences 方法中,我收到一条错误消息:

addOnCompleteListener (com.google.android.gms.tasks.OnCompleteListener) in Task cannot be applied to (my package name)

我搜索过帖子,几乎所有帖子都是关于 Firebase 的。任何帮助表示赞赏。谢谢!

代码如下:

 @SuppressWarnings("MissingPermission")
private void addGeofences() {
    if (!checkPermissions()) {
        showSnackbar(getString(R.string.insufficient_permissions));
        return;
    }

    mGeofencingClient.addGeofences(getGeofencingRequest(), getGeofencePendingIntent())
            .addOnCompleteListener(this);
}

注意:我在 removeGeofences 方法中也遇到了同样的错误。

我想通了这个问题...我忘记在 class 声明中实现 OnCompleteListener<Void>。更正后的代码如下所示:

public class MainActivity extends AppCompatActivity implements OnCompleteListener<Void>{