本文整理汇总了Java中com.google.android.gms.common.api.GoogleApiClient.isConnected方法的典型用法代码示例。如果您正苦于以下问题:Java GoogleApiClient.isConnected方法的具体用法?Java GoogleApiClient.isConnected怎么用?Java GoogleApiClient.isConnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.common.api.GoogleApiClient
的用法示例。
在下文中一共展示了GoogleApiClient.isConnected方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ClearAccount
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
public void ClearAccount(){
Log.i(TAG, "Clearing Google API Account");
GoogleApiClient mAPI = getGoogleApiClient();
if (mAPI != null) {
if(mAPI.isConnected()){
mAPI.clearDefaultAccountAndReconnect();
Log.i(TAG, "Clear account and reconnect called");
} else {
Log.w(TAG, "Google API client not connected when attempting disconnect");
Toast.makeText(this, "Google API not connected. Make sure WiFi is On.", Toast.LENGTH_LONG).show();
}
} else {
Log.w(TAG, "Google API was null when attempting to disconnect account");
}
stopSelf(mStartID);
}
示例2: startLocationUpdates
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@SuppressWarnings({"MissingPermission"})
public void startLocationUpdates(GoogleApiClient googleApiClient) {
// particular case:hace un requestLocationSettings y casi al mismo tiempo stop(),
// ,se recibe settingsResult:SUCCESS y luego hace startLocationUpdates y como
// no está conectado da error
if (!googleApiClient.isConnected()) {
return;
}
PendingResult<Status> result = LocationServices.FusedLocationApi.requestLocationUpdates(
googleApiClient, mLocationRequest, this);
result.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (!status.isSuccess()) {
Utils.logD(LOG_TAG, String.format("requestLocationUpdates returned an error:code:%s ," +
"message: %s", status.getStatusCode(), status.getStatusMessage()));
getActivity().finish();
}
}
}, 2, TimeUnit.SECONDS);
}
示例3: openLeaderboard
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
public void openLeaderboard() {
Log.d(LOG_TAG, "The user opened the leaderboard");
googleApiClientCallback myActivity = (googleApiClientCallback) getActivity();
GoogleApiClient myClient = myActivity.getGoogleApiClient();
if (myClient.isConnected()) {
startActivityForResult(
Games.Leaderboards.getAllLeaderboardsIntent(myClient),
RC_UNUSED);
} else {
BaseGameUtils.makeSimpleDialog(
getActivity(),
getString(R.string.leaderboards_not_available))
.show();
}
}
示例4: openAchievements
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
public void openAchievements() {
Log.d(LOG_TAG, "The user opened achievements");
googleApiClientCallback myActivity = (googleApiClientCallback) getActivity();
GoogleApiClient myClient = myActivity.getGoogleApiClient();
if (myClient.isConnected()) {
startActivityForResult(Games.Achievements.getAchievementsIntent(myClient),
RC_UNUSED);
} else {
BaseGameUtils.makeSimpleDialog(
getActivity(),
getString(R.string.achievements_not_available))
.show();
}
}
示例5: openLeaderboard
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
public void openLeaderboard() {
Log.d(LOG_TAG, "The user opened the leaderboard");
GoogleApiClientCallback myActivity = (GoogleApiClientCallback) getActivity();
GoogleApiClient myClient = myActivity.getGoogleApiClient();
if (myClient.isConnected()) {
startActivityForResult(
Games.Leaderboards.getAllLeaderboardsIntent(myClient),
RC_UNUSED);
} else {
BaseGameUtils.makeSimpleDialog(
getActivity(),
getString(R.string.leaderboards_not_available))
.show();
}
}
示例6: onUnsubscribed
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
protected void onUnsubscribed(GoogleApiClient locationClient) {
if (locationClient.isConnected()) {
try {
LocationServices.FusedLocationApi.setMockMode(locationClient, false);
} catch (SecurityException e) {
// if this happens then we couldn't have switched mock mode on in the first place,
// and the observer's onError will already have been called
}
}
if (mockLocationSubscription != null && !mockLocationSubscription.isUnsubscribed()) {
mockLocationSubscription.unsubscribe();
}
}
示例7: onUnsubscribed
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
protected void onUnsubscribed(GoogleApiClient apiClient) {
if (apiClient.isConnected()) {
ActivityRecognition.ActivityRecognitionApi.removeActivityUpdates(apiClient, getReceiverPendingIntent());
}
context.unregisterReceiver(receiver);
receiver = null;
}
示例8: initGoogleApiClient
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
private void initGoogleApiClient(GoogleApiClient googleApiClient) {
if (!googleApiClient.isConnected()) {
logger.log(TAG, "Google api client is not connected");
logger.log(TAG, "Google api client connecting");
ConnectionResult res = googleApiClient.blockingConnect();
if (!res.isSuccess()) {
throw new RuntimeException(THROWABLE_KEY_LOCATION);
}
logger.log(TAG, "Google api client connected");
}
}
示例9: setGoogleApiClient
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
public void setGoogleApiClient(GoogleApiClient googleApiClient) {
if (googleApiClient == null || !googleApiClient.isConnected()) {
mGoogleApiClient = null;
} else {
mGoogleApiClient = googleApiClient;
}
}
示例10: 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");
}
});
}
示例11: onUnsubscribed
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
@Override
protected void onUnsubscribed(GoogleApiClient locationClient) {
if (locationClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(locationClient, listener);
}
}
示例12: sendState
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
public static void sendState(final GoogleApiClient googleApiClient, final int state, final long timeStamp) {
if (googleApiClient == null) {
Log.e(TAG, "googleApiClient is null");
return;
}
if (!googleApiClient.isConnected()) {
Log.e(TAG, "googleApiClient disconnected");
googleApiClient.connect();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (!googleApiClient.isConnected())
Log.e(TAG, "googleApiClient reconnect failed");
else
sendState(googleApiClient, state, timeStamp);
}
}, 1000);
return;
}
Wearable.NodeApi.getConnectedNodes(googleApiClient).setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
@Override
public void onResult(@NonNull NodeApi.GetConnectedNodesResult getConnectedNodesResult) {
List<Node> nodes = getConnectedNodesResult.getNodes();
if (nodes == null || nodes.isEmpty()) {
Log.d(TAG, "Node not connected");
return;
}
DataMap config = new DataMap();
config.putInt("state", state);
if (timeStamp >= 0)
config.putLong("timestamp", timeStamp + 3000);
for (Node node : nodes)
Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), PATH_DND, config.toByteArray()).setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(@NonNull MessageApi.SendMessageResult sendMessageResult) {
Log.d(TAG, "Send message: " + sendMessageResult.getStatus().getStatusMessage());
}
});
}
});
}
示例13: uploadScore
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
/**
* Uploads the score to the GoogleGamesApi. Unlocks any relevant achievements
*
* @param score Score to be uploaded
*/
@Override
public void uploadScore(long score) {
// Get the GoogleApiClient from our parent activity
GoogleApiClientCallback myActivity = (GoogleApiClientCallback) getActivity();
GoogleApiClient myClient = myActivity.getGoogleApiClient();
// Submit our score
if (!myClient.isConnected()) {
// Let the user know they aren't signed in but their high score will be saved
// and uploaded when once they sign in
} else {
// Submit score to leaderboard
Games.Leaderboards.submitScore(
myClient,
getString(R.string.leaderboard_classic_mode),
score);
// Set flag to know we've uploaded this score.
mNormalActionsListener.onScoreUploaded(true);
// Increment number of Classic games played
Games.Achievements.increment(
myClient,
getString(R.string.achievement_patience),
1
);
// Check for high score achievements
if (score <= 900000) { // 15 minutes
Games.Achievements.unlock(
myClient,
getString(R.string.achievement_youre_getting_the_hang_of_this)
);
}
if (score <= 600000) { // 10 minutes
Games.Achievements.unlock(
myClient,
getString(R.string.achievement_youre_pretty_good_at_this)
);
}
if (score <= 300000) { // 5 minutes
Games.Achievements.unlock(
myClient,
getString(R.string.achievement_youre_crazy)
);
}
}
}
示例14: uploadScore
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
/**
* Uploads the score to the GoogleGamesApi. Unlocks any relevant achievements
*
* @param score Score to be uploaded
*/
@Override
public void uploadScore(long score) {
// Get the GoogleApiClient from our parent activity
GoogleApiClientCallback myActivity = (GoogleApiClientCallback) getActivity();
GoogleApiClient myClient = myActivity.getGoogleApiClient();
// Submit our score
if (!myClient.isConnected()) {
// Let the user know they aren't signed in but their high score will be saved
// and uploaded when once they sign in
} else {
Games.Leaderboards.submitScore(
myClient,
getString(R.string.leaderboard_time_attack),
score);
// Increment number of Classic games played
Games.Achievements.increment(
myClient,
getString(R.string.achievement_persistence),
1
);
// Check for high score achievements
if (score >= 2) {
Games.Achievements.unlock(
myClient,
getString(R.string.achievement_speed_beginner)
);
}
if (score >= 6) {
Games.Achievements.unlock(
myClient,
getString(R.string.achievement_speed_intermediate)
);
}
if (score >= 10) {
Games.Achievements.unlock(
myClient,
getString(R.string.achievement_speed_master)
);
}
}
}
示例15: checkGoogleApiClient
import com.google.android.gms.common.api.GoogleApiClient; //导入方法依赖的package包/类
private static void checkGoogleApiClient(GoogleApiClient googleApiClient) {
if(googleApiClient == null || !googleApiClient.isConnected()) {
throw new IllegalStateException("Google API client must be connected");
}
}