当前位置: 首页>>代码示例>>Java>>正文


Java GoogleApiClient.disconnect方法代码示例

本文整理汇总了Java中com.google.android.gms.common.api.GoogleApiClient.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Java GoogleApiClient.disconnect方法的具体用法?Java GoogleApiClient.disconnect怎么用?Java GoogleApiClient.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.gms.common.api.GoogleApiClient的用法示例。


在下文中一共展示了GoogleApiClient.disconnect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startLocationUpdate

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
private void startLocationUpdate(
    GoogleApiClient googleApiClient,
    LocationListener locationListener
) {
  boolean a = ActivityCompat.checkSelfPermission(getApplicationContext(),
      Manifest.permission.ACCESS_FINE_LOCATION
  ) != PackageManager.PERMISSION_GRANTED;
  boolean b = ActivityCompat.checkSelfPermission(getApplicationContext(),
      Manifest.permission.ACCESS_COARSE_LOCATION
  ) != PackageManager.PERMISSION_GRANTED;
  if (a && b) {
    googleApiClient.disconnect();
    return;
  }
  LocationServices.FusedLocationApi.requestLocationUpdates(
      googleApiClient,
      new LocationRequest().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY),
      locationListener);
}
 
开发者ID:drfonfon,项目名称:ITagAntiLost,代码行数:20,代码来源:LocationChangeService.java

示例2: onDataChanged

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
public void onDataChanged(DataEventBuffer dataEventBuffer) {
    GoogleApiClient googleApiClient = null;

    for (DataEvent event : dataEventBuffer) {
        if (event.getType() != DataEvent.TYPE_CHANGED) {
            continue;
        }

        DataItem dataItem = event.getDataItem();

        if (CommPaths.COMMAND_ALARM.equals(dataItem.getUri().getPath())) {
            LiteAlarmCommand liteAlarmCommand = ParcelPacker.getParcelable(dataItem.getData(), LiteAlarmCommand.CREATOR);

            if (googleApiClient == null) {
                googleApiClient = new GoogleApiClient.Builder(this)
                        .addApi(Wearable.API)
                        .build();

                googleApiClient.blockingConnect();
            }

            byte[] iconData = getByteArrayAsset(dataItem.getAssets().get(CommPaths.ASSET_ICON), googleApiClient);
            byte[] backgroundData = getByteArrayAsset(dataItem.getAssets().get(CommPaths.ASSET_BACKGROUND), googleApiClient);

            AlarmCommand alarmCommand = new AlarmCommand(liteAlarmCommand, backgroundData, iconData);
            alarm(alarmCommand);

            Wearable.DataApi.deleteDataItems(googleApiClient, dataItem.getUri()).await();
        }
    }

    if (googleApiClient != null) {
        googleApiClient.disconnect();
    }
}
 
开发者ID:matejdro,项目名称:WearVibrationCenter,代码行数:37,代码来源:PhoneCommandListener.java

示例3: onHandleIntent

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
  if (intent != null) {
    final String address = intent.getStringExtra(BleService.DEVICE_ADDRESS);
    if (address != null) {
      final GoogleApiClient googleApiClient =
          new GoogleApiClient.Builder(getApplicationContext())
              .addApi(LocationServices.API)
              .build();

      final LocationListener locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(final Location location) {
          if (location != null) {
            updateDeviceLocation(address, location);
            LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, this);
            googleApiClient.disconnect();
          }
        }
      };

      googleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
        @Override
        public void onConnected(@Nullable Bundle bundle) {
          startLocationUpdate(googleApiClient, locationListener);
        }

        @Override
        public void onConnectionSuspended(int i) {

        }
      });
      googleApiClient.connect();
    }
  }
}
 
开发者ID:drfonfon,项目名称:ITagAntiLost,代码行数:37,代码来源:LocationChangeService.java

示例4: getFusedLocation

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@ReactMethod
public void getFusedLocation( boolean forceNewLocation, final Promise promise) {
    try {
        if (!areProvidersAvailable()) {
            promise.reject(TAG, "No location provider found.");
            return;
        }
        if (!checkForPlayServices()) {
            promise.reject(TAG, "Install Google Play Services First and Try Again.");
            return;
        }
        if (ActivityCompat.checkSelfPermission(getReactApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getReactApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            promise.reject(TAG, "Appropriate permissions not given.");
            return;
        }
        final GoogleApiClient googleApiClient;
        LocationRequest request = buildLR();
        googleApiClient = new GoogleApiClient.Builder(getReactApplicationContext())
                .addApi(LocationServices.API)
                .build();
        googleApiClient.blockingConnect();
        final Location location;
        if(!forceNewLocation) {
            location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
        }
        else {
            location = null;
        }
        if (location == null) {
            LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, request, new LocationListener() {
                @Override
                public void onLocationChanged(Location l) {
                    LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, this);
                    googleApiClient.disconnect();
                    promise.resolve(convertLocationToJSON(l));
                }
            });
        } else {
            promise.resolve(convertLocationToJSON(location));
            googleApiClient.disconnect();
        }
    } catch (Exception ex) {
        Log.e(TAG, "Native Location Module ERR - " + ex.toString());
        promise.reject(TAG, ex.toString());
    }
}
 
开发者ID:MustansirZia,项目名称:react-native-fused-location,代码行数:47,代码来源:FusedLocationModule.java


注:本文中的com.google.android.gms.common.api.GoogleApiClient.disconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。