小编fps*_*li3的帖子

Android FusedLocationProviderApi:传入意图没有LocationResult或LocationAvailability

我正在尝试通过Google的FusedLocationProviderApi订阅位置更新.我想在后台接收更新,这样即使应用程序被杀,我也会收到更新.尽可能遵循在线文档,我编写了以下代码.注意:这是在intent服务中完成的,而不是在UI线程上完成的,这就是我使用阻塞连接/结果方法的原因.

private void startLocationServices(String deviceId, int pollingInterval) {
    Log.i(TAG, "Starting location services with interval: " + pollingInterval + "ms");
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    wakeLock.acquire();

    final GoogleApiClient googleApiClient =
            new GoogleApiClient.Builder(this)
                    .addApi(LocationServices.API)
                    .build();

    ConnectionResult result = googleApiClient.blockingConnect();

    if (!result.isSuccess() || !googleApiClient.isConnected()) {
        Log.e(TAG, "Failed to connect to Google Api");
        wakeLock.release();
        return;
    }

    LocationRequest locationRequest = new LocationRequest();
    locationRequest.setInterval(pollingInterval);
    locationRequest.setFastestInterval(10000);
    locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);

    Intent locationIntent = new Intent(this, GeoBroadcastReceiver.class);
    locationIntent.putExtra(EXTRA_LOCATION_UPDATE_DEVICE_ID, deviceId);
    locationIntent.setAction(GeoBroadcastReceiver.ACTION_LOCATION_UPDATE);
    PendingIntent locationPendingIntent = PendingIntent.getBroadcast(
            this, …
Run Code Online (Sandbox Code Playgroud)

android location

10
推荐指数
2
解决办法
1604
查看次数

即使在调用requestLayout之后,在Android视图上更改LayoutParams也没有任何效果

我遇到过两次或三次这种情况,我有一些看起来像这样的代码:

  ViewGroup.LayoutParams params = myView.getLayoutParams();
  params.height = 240;
  myView.requestLayout();
Run Code Online (Sandbox Code Playgroud)

或者:

  ViewGroup.LayoutParams params = myView.getLayoutParams();
  params.height = 240;
  myView.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud)

视图大小永远不会改变.我试过以下,没有运气:

  1. 呼叫forceLayout,具有讽刺意味的似乎不那么有力requestLayout,因为它没有通知View的父母需要布局.
  2. 覆盖onMeasure()以查看是否曾被调用(它不是).
  3. 确保我requestLayout在布局过程中没有进行调用.

我也尝试过调用requestLayout所有View的父母,如下所示:

  ViewParent parent = myView.getParent();
  while (parent != null) {
      parent.requestLayout();
      parent = parent.getParent();
  }
Run Code Online (Sandbox Code Playgroud)

这有效,但看起来真的很酷.我更愿意找到真正的解决方案.

我究竟做错了什么?

android android-layout android-measure

4
推荐指数
1
解决办法
783
查看次数