本文整理汇总了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);
}
示例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();
}
}
示例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();
}
}
}
示例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());
}
}