GeofencingRequest 无法解析为类型

GeofencingRequest cannot be resolved to a type

我正在尝试开发一个简单的 Android 应用程序,该应用程序请求为 Google Play 服务创建地理围栏并在发生转换时执行操作。

我想创建时出现了问题

GeofencingRequest mGeofencingRequest=new GeofencingRequest.Builder()
.build();

因为 Eclipse 警告我:

GeofencingRequest cannot be resolved to be a type.

我需要这个对象才能使用 addGeofences

所有其他导入和接口工作正常(已测试)。

  1. 我今天更新了 Google 使用 Android SDK 管理器播放服务;
  2. 我已将 Google_play_services 作为库包含到我的项目中;
  3. Android 项目构建目标在 Android 5.0.1;
  4. 我的 AndroidManifest 有编辑过的元数据字段 Google Play 服务;

非常感谢任何帮助。

我终于弄清楚问题是什么以及如何解决了。

我的工作区中 Google Play Service Lib 的副本没有更新到最新版本,尽管 Android SDK Mangager 另有说明。

无论如何,

  • 我刚刚从 Eclipse IDE 和 它所在的工作组文件夹;
  • 我已经从 SDK 文件夹中导入了一个全新的 google_play_service_lib 蚀.
  • 再次将 google_play_service_lib 添加到我的项目中解决了问题。

首先,您需要在 onCreate() 方法中实例化 GoogleClientApi

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

// Connect the client
mGoogleApiClient.connect();

然后,您可能想对 GeofencingApi 执行此操作:

LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, mGeofenceList, mGeofenceRequestIntent)
                .setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        if (status.isSuccess()) {
                            // Success
                            Log.i(Constants.APPTAG, "success!");
                        }
                    }
                });