@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); 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); } }
/** * Method called every time the options menu is invalidated/repainted. Shows/hides the sign out button * * @see android.app.Activity#onPrepareOptionsMenu(android.view.Menu) */ @Override public boolean onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); menu.findItem(R.id.sign_out).setVisible(GoogleSignIn.getLastSignedInAccount(this) != null); return true; }
if (!GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount((AppCompatActivity) getActivity()), fitnessOptions)) { GoogleSignIn.requestPermissions( this, REQUEST_OAUTH_REQUEST_CODE, GoogleSignIn.getLastSignedInAccount((AppCompatActivity) getActivity()), fitnessOptions); } else {
@Override public void onPause() { super.onPause(); // remove callbacks from refreshing handler.removeCallbacks(refreshRunnable); // set refreshing back to false if it was refreshing if (swipeRefreshLayout.isRefreshing()) { swipeRefreshLayout.setRefreshing(false); } // unregister the listener if (!GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount((AppCompatActivity) getActivity()))) { Log.d(TAG, "Not signed in..."); } else { Fitness.getSensorsClient((AppCompatActivity) getActivity(), GoogleSignIn.getLastSignedInAccount((AppCompatActivity) getActivity())) .remove(stepListener) .addOnCompleteListener( new OnCompleteListener<Boolean>() { @Override public void onComplete(@NonNull Task<Boolean> task) { if (task.isSuccessful() && task.getResult()) { Log.d(TAG, "Step Listener for steps was removed."); } else { Log.e(TAG, "Step Listener for steps was not removed.", task.getException()); } } } ); } }
/** * Starts the sign-in process and initializes the Drive client. */ private void signIn() { 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 public void onAttach(Context context) { super.onAttach(context); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken("YOUR_REQUEST_ID_TOKEN") .requestEmail() .build(); mGoogleSignInClient = GoogleSignIn.getClient(context, gso); mAuth = FirebaseAuth.getInstance(); }
if (!GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount((AppCompatActivity) getActivity()))) { Log.d(TAG, "Not signed in..."); } else { Fitness.getSensorsClient((AppCompatActivity) getActivity(), GoogleSignIn.getLastSignedInAccount((AppCompatActivity) getActivity())) .add( new SensorRequest.Builder()
.build(); mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); handleSignInResult(task); } }
@Override public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) { final int rowCount = data == null ? 0 : data.getCount(); if (BuildConfig.DEBUG) Log.d(TAG, "onLoadFinished found " + rowCount + " rows"); stats = stats.unionWith(new StatsState(data)); if (mAlreadyLoadedState && GoogleSignIn.getLastSignedInAccount(this) != null) saveToCloud(); else if (rowCount > 0) mPendingUpdateState = true; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sign_in); mAuth = FirebaseAuth.getInstance(); GoogleSignInOptions mGso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.google_web_client_id)) .requestEmail() .build(); mGoogleSignInClient = GoogleSignIn.getClient(this, mGso); mProgressBar = findViewById(R.id.pb_signin); PresenterInjector.injectSignInPresenter(this); findViewById(R.id.google_signin_btn).setOnClickListener(v -> mPresenter.handleLoginRequest()); extras = getIntent().getExtras(); mPresenter.start(extras); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { Log.w(TAG, e.getMessage()); Toast.makeText(this, "Google Sign In failed. Please try again.", Toast.LENGTH_SHORT).show(); } } }
/** * 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)); } }
public void backuptodrive(String path) { GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(Drive.SCOPE_FILE, Drive.SCOPE_APPFOLDER) .requestIdToken("YOUR_REQUEST_ID_TOKEN") .build(); mGoogleSignInClient = GoogleSignIn.getClient(getContext(), signInOptions); Intent signInIntent = mGoogleSignInClient.getSignInIntent(); startActivityForResult(signInIntent, RC_SIGN_IN); tmppath = path; }
@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); if(account != null) { firebaseAuthWithGoogle(account); } } catch (ApiException e) { Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); } } }
Drive.getDriveResourceClient(getContext(), GoogleSignIn.getLastSignedInAccount(getContext())).openFile(file, DriveFile.MODE_READ_ONLY); openFileTask .continueWithTask(task -> { Task<Void> discardTask = Drive.getDriveResourceClient(getContext(), GoogleSignIn.getLastSignedInAccount(getContext())).discardContents(contents); return discardTask; })
public void downloadinit() { GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(Drive.SCOPE_FILE, Drive.SCOPE_APPFOLDER) .requestIdToken("YOUR_REQUEST_ID_TOKEN") .build(); mGoogleSignInClient = GoogleSignIn.getClient(getContext(), signInOptions); Intent signInIntent = mGoogleSignInClient.getSignInIntent(); startActivityForResult(signInIntent, RC_SIGN_IN_DOWNLOAD); }
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); task.addOnSuccessListener( new OnSuccessListener<GoogleSignInAccount>() {
private void accessGoogleFit() { Fitness.getRecordingClient((AppCompatActivity) getActivity(), GoogleSignIn.getLastSignedInAccount((AppCompatActivity) getActivity())) .subscribe(DataType.AGGREGATE_STEP_COUNT_DELTA) .addOnSuccessListener(new OnSuccessListener<Void>() { Fitness.getRecordingClient((AppCompatActivity) getActivity(), GoogleSignIn.getLastSignedInAccount((AppCompatActivity) getActivity())) .subscribe(DataType.TYPE_STEP_COUNT_DELTA) .addOnSuccessListener(new OnSuccessListener<Void>() { Fitness.getRecordingClient((AppCompatActivity) getActivity(), GoogleSignIn.getLastSignedInAccount((AppCompatActivity) getActivity())) .subscribe(DataType.TYPE_DISTANCE_DELTA) .addOnSuccessListener(new OnSuccessListener<Void>() { Fitness.getHistoryClient((AppCompatActivity) getActivity(), GoogleSignIn.getLastSignedInAccount((AppCompatActivity) getActivity())) .readData(readRequest) .addOnSuccessListener(new OnSuccessListener<DataReadResponse>() {
super.onCreate(savedInstanceState); setContentView(R.layout.main); mGoogleSignInClient = GoogleSignIn.getClient(this, new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN) .requestScopes(Drive.SCOPE_APPFOLDER)