@Override protected void onStart() { super.onStart(); GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this); if (account != null) { HashMap<String, String> params = new HashMap<String, String>(); params.put("OS", "Android " + Build.VERSION.SDK_INT + " " + Build.VERSION.RELEASE); params.put("Device", Build.MANUFACTURER + " " + Build.MODEL); ChatWindowConfiguration config = new ChatWindowConfiguration( Config.license, Config.group, account.getDisplayName(), account.getEmail(), params ); launchChat(this, config); } else { signIn(); } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (fullScreenChatWindow != null) fullScreenChatWindow.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { // The Task returned from this call is always completed, no need to attach // a listener. Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); handleSignInResult(task); } else { Log.w("Chat", "Received unknown code " + requestCode); } }
public void init (final int instanceID) { script_id = instanceID; GUtils.setScriptInstance(script_id); if (GUtils.checkGooglePlayService(activity)) { Log.d(TAG, "Play Service Available."); } GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN) .requestScopes(new Scope(Scopes.GAMES)) .requestEmail() .build(); mGoogleSignInClient = GoogleSignIn.getClient(activity, gso); Log.d(TAG, "Google::Initialized"); onStart(); }
private void signInSilently() { if (isConnected()) { return; } GoogleSignInClient signInClient = GoogleSignIn.getClient(activity, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); signInClient.silentSignIn().addOnCompleteListener(activity, new OnCompleteListener<GoogleSignInAccount>() { @Override public void onComplete(@NonNull Task<GoogleSignInAccount> task) { if (task.isSuccessful()) { // The signed in account is stored in the task's result. try { mAccount = task.getResult(ApiException.class); succeedSignIn(); } catch (ApiException e) { Log.w(TAG, "SignInResult::Failed code=" + e.getStatusCode() + ", Message: " + e.getStatusMessage()); } } else { // Player will need to sign-in explicitly using via UI Log.d(TAG, "Silent::Login::Failed"); } } }); }
@Override public void hideHintAndShowMap() { super.hideHintAndShowMap(); if (mCurrentLocation != null) { LatLng currentLatLng = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()); if (path.isEmpty() && CoordinatesUtility.get2DDistanceInKm(currentLatLng, poi) < KM_DISTANCE_HINT) { myScore = getTotalScore().getScore(); SpaceRace.messageManager.sendToAllReliably( new EndMessageBuilder() .setType(END_MATCH) .setScore(myScore) .build() ); Games.getLeaderboardsClient(this, GoogleSignIn.getLastSignedInAccount(this)) .submitScore(getString(R.string.leaderboard_id), myScore); } } }
@Override public void receiveEndMatch(String message) { opponentScore = EndMessageBuilder.decodeScore(message); myScore = getTotalScore().getScore(); Games.getLeaderboardsClient(this, GoogleSignIn.getLastSignedInAccount(this)) .submitScore(getString(R.string.leaderboard_id), myScore); SpaceRace.messageManager.sendToAllReliably( new EndMessageBuilder() .setType(EndMatchReceiver.ACK_END_MATCH) .setScore(myScore) .build() ); launchEndMatchActivity(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); NetworkingUtility.registerListener(this); disablePlayButtons(); mGoogleSignInClient = GoogleSignIn.getClient(this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); if (!BaseGameUtils.verifySampleSetup(this, R.string.app_id)) { Log.w("SIGNIN", "*** Warning: setup problems detected. Sign in may not work!"); } // start the sign-in flow Log.d("SIGNIN", "Sign-in button clicked"); startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN); LanguageManager.languageManagement(this); }
@Override protected void onResume() { super.onResume(); if (!BaseGameUtils.verifySampleSetup(this, R.string.app_id)) { Log.w("SIGNIN", "*** Warning: setup problems detected. Sign in may not work!"); } Log.d("SIGNIN", "Sign-in silently"); if (!NetworkingUtility.isNetworkAvailable() || GoogleSignIn.getLastSignedInAccount(SpaceRace.getAppContext()) == null || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED) disablePlayButtons(); signInSilently(); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { // Google Sign In was successful, authenticate with Firebase GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { // Google Sign In failed, update UI appropriately Log.w(TAG, "Google sign in failed", e); // ... } } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { // Google Sign In was successful, authenticate with Firebase GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { // Google Sign In failed, update UI appropriately Log.w(TAG, "Google sign in failed", e); // [START_EXCLUDE] updateUI(null); // [END_EXCLUDE] } } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_RESOLVE_ERROR) { if (resultCode == RESULT_OK) { Task<GoogleSignInAccount> getAccountTask = GoogleSignIn.getSignedInAccountFromIntent(data); if (getAccountTask.isSuccessful()) { initializeDriveClient(getAccountTask.getResult()); Toast.makeText(getContext(), R.string.pref_title_backup_active_connected, Toast.LENGTH_SHORT).show(); } else { Log.e(TAG, "Sign-in failed."); Toast.makeText(getContext(), R.string.pref_title_backup_active_failed, Toast.LENGTH_LONG).show(); } } } }
private void loadDriveApiClients() { Set<Scope> requiredScopes = new HashSet<>(2); requiredScopes.add(Drive.SCOPE_FILE); requiredScopes.add(Drive.SCOPE_APPFOLDER); GoogleSignInAccount signInAccount = GoogleSignIn.getLastSignedInAccount(getContext()); if (signInAccount != null && signInAccount.getGrantedScopes().containsAll(requiredScopes)) { initializeDriveClient(signInAccount); } else { GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(Drive.SCOPE_FILE) .requestScopes(Drive.SCOPE_APPFOLDER) .build(); GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(getActivity(), signInOptions); startActivityForResult(googleSignInClient.getSignInIntent(), REQUEST_RESOLVE_ERROR); } }
public void subscribe() { //connect to the step count. Fitness.getRecordingClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext())) .subscribe(DataType.TYPE_STEP_COUNT_DELTA) .addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { logthis("Subscribed to the Recording API"); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { logthis("failed to subscribe to the Recording API"); } }); }
private Task<DataSet> displayTodayData() { Log.i(TAG, "Reading History API results for today of Steps"); return Fitness.getHistoryClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext())) .readDailyTotal(DataType.TYPE_STEP_COUNT_DELTA) .addOnSuccessListener(new OnSuccessListener<DataSet>() { @Override public void onSuccess(DataSet dataSet) { Log.i(TAG, "Reading History API results for today"); showDataSet(dataSet); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.i(TAG, "Failed to read DailyTotal for Steps."); } }); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_GET_AUTH_CODE) { // [START get_auth_code] Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); String authCode = account.getServerAuthCode(); // Show signed-un UI updateUI(account); // TODO(developer): send code to server and exchange for access/refresh/ID tokens } catch (ApiException e) { Log.w(TAG, "Sign-in failed", e); updateUI(null); } // [END get_auth_code] } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); handleSignInResult(task); } // Handling a user-recoverable auth exception if (requestCode == RC_RECOVERABLE) { if (resultCode == RESULT_OK) { getContacts(); } else { Toast.makeText(this, R.string.msg_contacts_failed, Toast.LENGTH_SHORT).show(); } } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_SIGN_IN) { if (resultCode != RESULT_OK) { // Sign-in may fail or be cancelled by the user. For this sample, sign-in is // required and is fatal. For apps where sign-in is optional, handle appropriately Log.e(TAG, "Sign-in failed."); finish(); return; } Task<GoogleSignInAccount> getAccountTask = GoogleSignIn.getSignedInAccountFromIntent(data); if (getAccountTask.isSuccessful()) { initializeDriveResourceClient(getAccountTask.getResult()); } else { Log.e(TAG, "Sign-in failed."); finish(); } } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_SIGN_IN) { if (resultCode == RESULT_OK) { Log.i(TAG, "Signed in successfully"); Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); if (task.isSuccessful()) { onSignInSuccess(task.getResult()); } else { Log.e(TAG, "Unable to retrieve signed in account.", task.getException()); finish(); } } else { Log.e(TAG, "Unable to sign in, result code " + resultCode); } } }
/** * Handles resolution callbacks. */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_SIGN_IN) { if (resultCode != RESULT_OK) { // Sign-in may fail or be cancelled by the user. For this sample, sign-in is // required and is fatal. For apps where sign-in is optional, handle appropriately Log.e(TAG, "Sign-in failed."); finish(); return; } // We can use last signed in account here because we know the account has Drive scopes initializeDriveClient(GoogleSignIn.getLastSignedInAccount(this)); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(intent); try { GoogleSignInAccount account = task.getResult(ApiException.class); onConnected(account); } catch (ApiException apiException) { String message = apiException.getMessage(); if (message == null || message.isEmpty()) { message = getString(R.string.signin_other_error); } onDisconnected(); new AlertDialog.Builder(this) .setMessage(message) .setNeutralButton(android.R.string.ok, null) .show(); } } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Create the client used to sign in. mGoogleSignInClient = GoogleSignIn.getClient(this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); // set up a click listener for everything we care about for (int id : CLICKABLES) { findViewById(id).setOnClickListener(this); } switchToMainScreen(); checkPlaceholderIds(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Create the Google API Client with access to Games // Create the client used to sign in. mGoogleSignInClient = GoogleSignIn.getClient(this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); // Setup signin and signout buttons findViewById(R.id.sign_out_button).setOnClickListener(this); findViewById(R.id.sign_in_button).setOnClickListener(this); mDataView = findViewById(R.id.data_view); mTurnTextView = findViewById(R.id.turn_counter_view); checkPlaceholderIds(); }
@Override protected void onCreate(Bundle savedInstanceState) { log("onCreate."); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Create the client used to sign in. mGoogleSignInClient = GoogleSignIn.getClient(this, new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN) // Since we are using SavedGames, we need to add the SCOPE_APPFOLDER to access Google Drive. .requestScopes(Drive.SCOPE_APPFOLDER) .build()); for (int id : LEVEL_BUTTON_IDS) { findViewById(id).setOnClickListener(this); } findViewById(R.id.button_next_world).setOnClickListener(this); findViewById(R.id.button_prev_world).setOnClickListener(this); findViewById(R.id.button_sign_in).setOnClickListener(this); findViewById(R.id.button_sign_out).setOnClickListener(this); ((RatingBar) findViewById(R.id.gameplay_rating)).setOnRatingBarChangeListener(this); mSaveGame = new SaveGame(); updateUi(); checkPlaceholderIds(); }
/** * Handles resolution callbacks. */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_SIGN_IN) { if (resultCode != RESULT_OK) { // Sign-in may fail or be cancelled by the user. For this sample, sign-in is // required and is fatal. For apps where sign-in is optional, handle appropriately Log.e(TAG, "Sign-in failed."); finish(); return; } Task<GoogleSignInAccount> getAccountTask = GoogleSignIn.getSignedInAccountFromIntent(data); if (getAccountTask.isSuccessful()) { initializeDriveClient(getAccountTask.getResult()); } else { Log.e(TAG, "Sign-in failed."); finish(); } } }
/** * Starts the sign-in process and initializes the Drive client. */ protected void signIn() { Set<Scope> requiredScopes = new HashSet<>(2); requiredScopes.add(Drive.SCOPE_FILE); requiredScopes.add(Drive.SCOPE_APPFOLDER); GoogleSignInAccount signInAccount = GoogleSignIn.getLastSignedInAccount(this); if (signInAccount != null && signInAccount.getGrantedScopes().containsAll(requiredScopes)) { initializeDriveClient(signInAccount); } else { GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(Drive.SCOPE_FILE) .requestScopes(Drive.SCOPE_APPFOLDER) .build(); GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(this, signInOptions); startActivityForResult(googleSignInClient.getSignInIntent(), REQUEST_CODE_SIGN_IN); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .build(); mGoogleSignInClient = GoogleSignIn.getClient(this, gso); }
public static void signIn(AppCompatActivity activity) { String defaultWebClientId = activity.getString(R.string.default_web_client_id); GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(defaultWebClientId) .requestEmail() .build(); GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(activity, googleSignInOptions); Intent signInIntent = googleSignInClient.getSignInIntent(); activity.startActivityForResult(signInIntent, AppConstants.GOOGLE_SIGN_IN); }
public static void analyseGoogleLoginResult(Intent data, AppCompatActivity activity) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); GoogleAuthenticationUtils.authenticateInFirebaseUsingGoogleAccount(account, activity); } catch (ApiException e) { Toast.makeText(activity, R.string.authentication_failed, Toast.LENGTH_SHORT).show(); } }
public GoogleAuthenticator(Activity context) { super(context); // Configure sign-in to request the user's ID, email address, and basic // profile. ID and basic profile are included in DEFAULT_SIGN_IN. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(mContext.getString(R.string.default_web_client_id)) .requestEmail() .build(); // Build a GoogleSignInClient with the options specified by gso. mGoogleSignInClient = GoogleSignIn.getClient(mContext, gso); }
/** * Listener for result from sign in request. * Must be called in onActivityResult callback of parent context */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { // The Task returned from this call is always completed, no need to attach // a listener. Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); handleSignInResult(task); } }
private void initGoogle(String accessToken) { GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .requestIdToken(accessToken) .build(); mGoogleSignInClient = GoogleSignIn.getClient(context, gso); }
public void fromActivityResult(int requestCode, Intent data){ if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); onLoginListener.onSuccess(account); } catch (ApiException e) { onLoginListener.onFailed(e+""); } } }
protected void configGoogleSignIn() { GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.default_web_client_id)) .requestEmail() .build(); mGoogleSignInClient = GoogleSignIn.getClient(this, gso); mAuth = FirebaseAuth.getInstance(); }
@Override public void onStart() { super.onStart(); GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this); updateUI(account); if (account != null) { googleSignInAccount = account; mAuthorizedAccount = account.getAccount(); GetListOfBlogTask task = new GetListOfBlogTask(mAuthorizedAccount); task.execute(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_google); // Views mStatusTextView = findViewById(R.id.status); mDetailTextView = findViewById(R.id.detail); // Button listeners findViewById(R.id.sign_in_button).setOnClickListener(this); findViewById(R.id.sign_out_button).setOnClickListener(this); findViewById(R.id.disconnect_button).setOnClickListener(this); // [START config_signin] // Configure Google Sign In GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.default_web_client_id)) .requestEmail() .build(); // [END config_signin] mGoogleSignInClient = GoogleSignIn.getClient(this, gso); // [START initialize_auth] mAuth = FirebaseAuth.getInstance(); // [END initialize_auth] }
/** * Set up the Drive API client. * * @param prefs The SharedPreferences * @return Whether the setup was successful */ private boolean setupClient(@NonNull SharedPreferences prefs) { final GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(Drive.SCOPE_APPFOLDER) .build(); final GoogleSignInClient signInClient = GoogleSignIn.getClient(mContext, signInOptions); try { final GoogleSignInAccount signInAccount = Tasks.await(signInClient.silentSignIn()); mClient = Drive.getDriveClient(mContext, signInAccount); mResourceClient = Drive.getDriveResourceClient(mContext, signInAccount); Log.d(TAG, "Connection successful. sync: " + mShouldSync + " media: " + mMediaMounted); return true; } catch(ExecutionException e) { final ApiException result = (ApiException)e.getCause(); switch(result.getStatusCode()) { case GoogleSignInStatusCodes.SIGN_IN_REQUIRED: case GoogleSignInStatusCodes.INVALID_ACCOUNT: Log.i(TAG, "User not signed in. Disabling photo syncing."); prefs.edit().putBoolean(FlavordexApp.PREF_SYNC_PHOTOS, false).apply(); break; case GoogleSignInStatusCodes.API_NOT_CONNECTED: case GoogleSignInStatusCodes.NETWORK_ERROR: case GoogleSignInStatusCodes.INTERNAL_ERROR: Log.i(TAG, "Google Drive service unavailable. Disabling photo syncing."); prefs.edit().putBoolean(FlavordexApp.PREF_SYNC_PHOTOS, false).apply(); } Log.w(TAG, "Connection failed! Reason: " + result.getMessage()); } catch(InterruptedException ignored) { } return false; }
/** * Sign in to the Google Drive service. */ private void signInDrive() { final Context context = getContext(); if(context == null) { return; } final GoogleSignInOptions options = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(Drive.SCOPE_APPFOLDER) .build(); final GoogleSignInClient client = GoogleSignIn.getClient(context, options); startActivityForResult(client.getSignInIntent(), REQUEST_DRIVE_SIGNIN); }
private boolean loadDriveApiClients() { Set<Scope> requiredScopes = new HashSet<>(2); requiredScopes.add(Drive.SCOPE_FILE); requiredScopes.add(Drive.SCOPE_APPFOLDER); GoogleSignInAccount signInAccount = GoogleSignIn.getLastSignedInAccount(this); if (signInAccount != null && signInAccount.getGrantedScopes().containsAll(requiredScopes)) { mDriveClient = Drive.getDriveClient(getApplicationContext(), signInAccount); mDriveResourceClient = Drive.getDriveResourceClient(getApplicationContext(), signInAccount); return true; } return false; }
/** * Launches the Google SignIn activity to request OAuth permission for the user. */ private void requestOAuthPermission() { FitnessOptions fitnessOptions = getFitnessSignInOptions(); GoogleSignIn.requestPermissions( this, REQUEST_OAUTH, GoogleSignIn.getLastSignedInAccount(getContext()), fitnessOptions); }
/** * Creates and executes a {@link SessionInsertRequest} using {@link * com.google.android.gms.fitness.SessionsClient} to insert a session. */ private Task<Void> insertSessionData() { //First, create a new session and an insertion request. SessionInsertRequest insertRequest = insertFitnessSession(); // [START insert_session] // Then, invoke the Sessions API to insert the session and await the result, // which is possible here because of the AsyncTask. Always include a timeout when // calling await() to avoid hanging that can occur from the service being shutdown // because of low memory or other conditions. sendmessage( "Inserting the session in the session API"); return Fitness.getSessionsClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext())) .insertSession(insertRequest) .addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { // At this point, the session has been inserted and can be read. sendmessage( "Session insert was successful!"); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { sendmessage( "There was a problem inserting the session: " + e.getLocalizedMessage()); } }); // [END insert_session] }