當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。