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


Java GoogleApiClient.connect方法代码示例

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


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

示例1: displayLocationSettingsRequest

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
public void displayLocationSettingsRequest(final Activity activity) {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity)
            .addApi(LocationServices.API).build();
    googleApiClient.connect();

    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(mAccuracy);
    locationRequest.setInterval(mInterval);
    locationRequest.setFastestInterval(mInterval / 2);

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(locationRequest);
    builder.setAlwaysShow(false);

    final PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
    result.setResultCallback(new LocationResultCallback(activity));
}
 
开发者ID:philiWeitz,项目名称:react-native-location-switch,代码行数:19,代码来源:LocationSwitch.java

示例2: call

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
public void call(Subscriber<? super T> subscriber) {

    final GoogleApiClient apiClient = createApiClient(subscriber);
    try {
        apiClient.connect();
    } catch (Throwable ex) {
        subscriber.onError(ex);
    }

    subscriber.add(Subscriptions.create(new Action0() {
        @Override
        public void call() {
            if (apiClient.isConnected() || apiClient.isConnecting()) {
                onUnsubscribed(apiClient);
                apiClient.disconnect();
            }
        }
    }));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:BaseObservable.java

示例3: subscribe

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
public final void subscribe(FlowableEmitter<T> emitter) throws Exception {
    final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter));

    try {
        apiClient.connect();
    } catch (Throwable ex) {
        emitter.onError(ex);
    }

    emitter.setCancellable(new Cancellable() {
        @Override
        public void cancel() throws Exception {
            if (apiClient.isConnected()) {
                RxLocationFlowableOnSubscribe.this.onUnsubscribed(apiClient);
            }

            apiClient.disconnect();
        }
    });
}
 
开发者ID:TechIsFun,项目名称:RxJava2-weather-example,代码行数:22,代码来源:RxLocationFlowableOnSubscribe.java

示例4: subscribe

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
public final void subscribe(MaybeEmitter<T> emitter) throws Exception {
    final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter));

    try {
        apiClient.connect();
    } catch (Throwable ex) {
        emitter.onError(ex);
    }

    emitter.setCancellable(new Cancellable() {
        @Override
        public void cancel() throws Exception {
            if (apiClient.isConnected()) {
                RxLocationMaybeOnSubscribe.this.onUnsubscribed(apiClient);
            }

            apiClient.disconnect();
        }
    });
}
 
开发者ID:TechIsFun,项目名称:RxJava2-weather-example,代码行数:22,代码来源:RxLocationMaybeOnSubscribe.java

示例5: subscribe

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
public final void subscribe(SingleEmitter<T> emitter) throws Exception {
    final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter));

    try {
        apiClient.connect();
    } catch (Throwable ex) {
        emitter.onError(ex);
    }

    emitter.setCancellable(new Cancellable() {
        @Override
        public void cancel() throws Exception {
            if (apiClient.isConnected()) {
                RxLocationSingleOnSubscribe.this.onUnsubscribed(apiClient);
            }

            apiClient.disconnect();
        }
    });
}
 
开发者ID:TechIsFun,项目名称:RxJava2-weather-example,代码行数:22,代码来源:RxLocationSingleOnSubscribe.java

示例6: resolveConnectionFailure

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
/**
 * Resolve a connection failure from
 * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)}
 *
 * @param activity the Activity trying to resolve the connection failure.
 * @param client the GoogleAPIClient instance of the Activity.
 * @param result the ConnectionResult received by the Activity.
 * @param requestCode a request code which the calling Activity can use to identify the result
 *                    of this resolution in onActivityResult.
 * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved.
 * @return true if the connection failure is resolved, false otherwise.
 */
public static boolean resolveConnectionFailure(Activity activity,
                                               GoogleApiClient client, ConnectionResult result, int requestCode,
                                               int fallbackErrorMessage) {

    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(activity, requestCode);
            return true;
        } catch (IntentSender.SendIntentException e) {
            // The intent was canceled before it was sent.  Return to the default
            // state and attempt to connect to get an updated ConnectionResult.
            client.connect();
            return false;
        }
    } else {
        // not resolvable... so show an error message
        int errorCode = result.getErrorCode();
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
                activity, requestCode);
        if (dialog != null) {
            dialog.show();
        } else {
            // no built-in dialog: show the fallback error message
            showAlert(activity, activity.getString(fallbackErrorMessage));
        }
        return false;
    }
}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:41,代码来源:BaseGameUtils.java

示例7: subscribe

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
public final void subscribe(SingleEmitter<T> emitter) throws Exception {
    final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter));

    try {
        apiClient.connect();
    } catch (Throwable ex) {
        emitter.onError(ex);
    }

    emitter.setCancellable(() -> {
        if (apiClient.isConnected()) {
            onUnsubscribed(apiClient);
        }

        apiClient.disconnect();
    });
}
 
开发者ID:florent37,项目名称:RxGps,代码行数:19,代码来源:RxLocationSingleOnSubscribe.java

示例8: subscribe

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
public final void subscribe(FlowableEmitter<T> emitter) throws Exception {
    final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter));

    try {
        apiClient.connect();
    } catch (Throwable ex) {
        emitter.onError(ex);
    }

    emitter.setCancellable(() -> {
        if (apiClient.isConnected()) {
            onUnsubscribed(apiClient);
        }

        apiClient.disconnect();
    });
}
 
开发者ID:florent37,项目名称:RxGps,代码行数:19,代码来源:RxLocationFlowableOnSubscribe.java

示例9: subscribe

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
public final void subscribe(MaybeEmitter<T> emitter) throws Exception {
    final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter));

    try {
        apiClient.connect();
    } catch (Throwable ex) {
        emitter.onError(ex);
    }

    emitter.setCancellable(() -> {
        if (apiClient.isConnected()) {
            onUnsubscribed(apiClient);
        }

        apiClient.disconnect();
    });
}
 
开发者ID:florent37,项目名称:RxGps,代码行数:19,代码来源:RxLocationMaybeOnSubscribe.java

示例10: resolveConnectionFailure

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
/**
 * Resolve a connection failure from
 * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)}
 *
 * @param activity the Activity trying to resolve the connection failure.
 * @param client the GoogleAPIClient instance of the Activity.
 * @param result the ConnectionResult received by the Activity.
 * @param requestCode a request code which the calling Activity can use to identify the result
 *                    of this resolution in onActivityResult.
 * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved.
 * @return true if the connection failure is resolved, false otherwise.
 */
public static boolean resolveConnectionFailure(Activity activity,
                                               GoogleApiClient client, ConnectionResult result, int requestCode,
                                               String fallbackErrorMessage) {

    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(activity, requestCode);
            return true;
        } catch (IntentSender.SendIntentException e) {
            // The intent was canceled before it was sent.  Return to the default
            // state and attempt to connect to get an updated ConnectionResult.
            client.connect();
            return false;
        }
    } else {
        // not resolvable... so show an error message
        int errorCode = result.getErrorCode();
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
                activity, requestCode);
        if (dialog != null) {
            dialog.show();
        } else {
            // no built-in dialog: show the fallback error message
            showAlert(activity, fallbackErrorMessage);
        }
        return false;
    }
}
 
开发者ID:Magicrafter13,项目名称:1946,代码行数:41,代码来源:BaseGameUtils.java

示例11: checkAvailability

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void checkAvailability(@NonNull final Context context, @NonNull PaymentMethod paymentMethod,
                              @NonNull final PaymentMethodAvailabilityCallback callback) {
    Log.d(TAG, "checkAvailability");

    GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
    int result = googleAPI.isGooglePlayServicesAvailable(context);

    if (result != ConnectionResult.SUCCESS) {
        callback.onFail(new GoogleApiClientNotInitializedException("Google API not available"));
    }
    final GoogleApiClient googleApiClient = getGoogleApiClient(context);

    if (googleApiClient != null) {
        googleApiClient.connect();
        Wallet.Payments.isReadyToPay(googleApiClient).setResultCallback(
                new ResultCallback<BooleanResult>() {
                    @Override
                    public void onResult(@NonNull BooleanResult booleanResult) {
                        if (booleanResult.getStatus().isSuccess()) {
                            callback.onSuccess(booleanResult.getValue());
                        } else {
                            Log.e(TAG, "isReadyToPay:" + booleanResult.getStatus());
                            String errorMessage = booleanResult.getStatus().getStatusCode()
                                    + booleanResult.getStatus().getStatusMessage();
                            callback.onFail(new Throwable(errorMessage));
                        }
                    }
                });
    } else {
        callback.onFail(new GoogleApiClientNotInitializedException(
                "Google API client is null or not connected"));
    }
}
 
开发者ID:Adyen,项目名称:adyen-android,代码行数:36,代码来源:AndroidPayService.java

示例12: logoutGoogle

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
private static void logoutGoogle(GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) {
    if (mGoogleApiClient == null) {
        mGoogleApiClient = GoogleApiHelper.createGoogleApiClient(fragmentActivity);
    }

    if (!mGoogleApiClient.isConnected()) {
        mGoogleApiClient.connect();
    }

    final GoogleApiClient finalMGoogleApiClient = mGoogleApiClient;
    mGoogleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
        @Override
        public void onConnected(@Nullable Bundle bundle) {
            if (finalMGoogleApiClient.isConnected()) {
                Auth.GoogleSignInApi.signOut(finalMGoogleApiClient).setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(@NonNull Status status) {
                        if (status.isSuccess()) {
                            LogUtil.logDebug(TAG, "User Logged out from Google");
                        } else {
                            LogUtil.logDebug(TAG, "Error Logged out from Google");
                        }
                    }
                });
            }
        }

        @Override
        public void onConnectionSuspended(int i) {
            LogUtil.logDebug(TAG, "Google API Client Connection Suspended");
        }
    });
}
 
开发者ID:rozdoum,项目名称:social-app-android,代码行数:34,代码来源:LogoutHelper.java

示例13: resolveConnectionFailure

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
public static boolean resolveConnectionFailure(Activity activity,
                                               GoogleApiClient client, ConnectionResult result, int requestCode,
                                               String fallbackErrorMessage) {

    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(activity, requestCode);
            return true;
        } catch (IntentSender.SendIntentException e) {
            // The intent was canceled before it was sent.  Return to the default
            // state and attempt to connect to get an updated ConnectionResult.
            client.connect();
            return false;
        }
    } else {
        // not resolvable... so show an error message
        int errorCode = result.getErrorCode();
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
                activity, requestCode);
        if (dialog != null) {
            dialog.show();
        } else {
            // no built-in dialog: show the fallback error message
            showAlert(activity, fallbackErrorMessage);
        }
        return false;
    }
}
 
开发者ID:Augugrumi,项目名称:SpaceRace,代码行数:29,代码来源:BaseGameUtils.java

示例14: resolveConnectionFailure

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
/**
 * Resolve a connection failure from
 * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)}
 *
 * @param activity             the Activity trying to resolve the connection failure.
 * @param client               the GoogleAPIClient instance of the Activity.
 * @param result               the ConnectionResult received by the Activity.
 * @param requestCode          a request code which the calling Activity can use to identify the result
 *                             of this resolution in onActivityResult.
 * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved.
 * @return true if the connection failure is resolved, false otherwise.
 */
public static boolean resolveConnectionFailure(Activity activity,
                                               GoogleApiClient client, ConnectionResult result, int requestCode,
                                               String fallbackErrorMessage) {

    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(activity, requestCode);
            return true;
        } catch (IntentSender.SendIntentException e) {
            // The intent was canceled before it was sent.  Return to the default
            // state and attempt to connect to get an updated ConnectionResult.
            client.connect();
            return false;
        }
    } else {
        // not resolvable... so show an error message
        int errorCode = result.getErrorCode();
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
                activity, requestCode);
        if (dialog != null) {
            dialog.show();
        } else {
            // no built-in dialog: show the fallback error message
            showAlert(activity, fallbackErrorMessage);
        }
        return false;
    }
}
 
开发者ID:jaysondc,项目名称:TripleTap,代码行数:41,代码来源:BaseGameUtils.java

示例15: resolveConnectionFailure

import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
/**
 * Resolve a connection failure from
 * {@link com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)}
 *
 * @param activity             the Activity trying to resolve the connection failure.
 * @param client               the GoogleAPIClient instance of the Activity.
 * @param result               the ConnectionResult received by the Activity.
 * @param requestCode          a request code which the calling Activity can use to identify the result
 *                             of this resolution in onActivityResult.
 * @param fallbackErrorMessage a generic error message to display if the failure cannot be resolved.
 * @return true if the connection failure is resolved, false otherwise.
 */
public static boolean resolveConnectionFailure(Activity activity,
                                               GoogleApiClient client, ConnectionResult result, int requestCode,
                                               int fallbackErrorMessage) {

    if (result.hasResolution()) {
        try {
            result.startResolutionForResult(activity, requestCode);
            return true;
        } catch (IntentSender.SendIntentException e) {
            // The intent was canceled before it was sent.  Return to the default
            // state and attempt to connect to get an updated ConnectionResult.
            client.connect();
            return false;
        }
    } else {
        // not resolvable... so show an error message
        int errorCode = result.getErrorCode();
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
                activity, requestCode);
        if (dialog != null) {
            dialog.show();
        } else {
            // no built-in dialog: show the fallback error message
            showAlert(activity, activity.getString(fallbackErrorMessage));
        }
        return false;
    }
}
 
开发者ID:TheAndroidMaster,项目名称:Asteroid,代码行数:41,代码来源:BaseGameUtils.java


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