List of usage examples for android.accounts Account Account
public Account(@NonNull Account other, @NonNull String accessId)
From source file:com.nbos.phonebook.sync.authenticator.AuthenticatorActivity.java
/** * //from www . java 2s.c o m * Called when response is received from the server for authentication * request. See onAuthenticationResult(). Sets the * AccountAuthenticatorResult which is sent back to the caller. Also sets * the authToken in AccountManager for this account. * * @param the confirmCredentials result. */ protected void finishLogin() { Log.i(tag, "finishLogin()"); final Account account = new Account(mUsername, Constants.ACCOUNT_TYPE); if (mRequestNewAccount) { mAccountManager.addAccountExplicitly(account, mPassword, null); mAccountManager.setUserData(account, Constants.PHONE_NUMBER_KEY, countryCode + mPhone); // Set contacts sync for this account. ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); } else { mAccountManager.setPassword(account, mPassword); } final Intent intent = new Intent(); mAuthtoken = mPassword; intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); if (mAuthtokenType != null && mAuthtokenType.equals(Constants.AUTHTOKEN_TYPE)) intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthtoken); Db.deleteServerData(getApplicationContext()); setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); }
From source file:com.androidexperiments.sprayscape.unitydriveplugin.GoogleDriveUnityPlayerActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { Log.i(TAG, "onActivityResult(" + requestCode + ", " + resultCode + ", " + data + ")"); UnityPlayer.UnitySendMessage("OnActivityResultListener", "OnActivityResult", requestCode + "," + resultCode + "," + data); switch (requestCode) { case REQUEST_CODE_ACCOUNT_SELECTED: { if (resultCode == RESULT_OK) { final String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); String accountType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE); SharedPreferences prefs = getPreferences(MODE_PRIVATE); final SharedPreferences.Editor e = prefs.edit(); e.putString(GOOGLE_ACCOUNT_NAME, accountName); e.apply();//from w w w. j a v a 2 s . co m Log.i(TAG, "user selected account: " + accountName + " type: " + accountType + " saved to shared preferences"); account = new Account(accountName, accountType); // TODO: maybe don't assume the user was trying to upload? // try uploading again //uploadFile(lastDriveFolderName, lastDriveFileName, lastLocalPath, lastCallbackObjectName); driveService = initDriveServiceFromAccount(account, lastCallbackObjectName); } else { // user cancel the account picker without selecting.... UnityPlayer.UnitySendMessage(lastCallbackObjectName, CALLBACK_METHOD_DRIVE_ACCOUNT_SELECTION_CANCELED, "" + resultCode); } break; } case REQUEST_CODE_RECOVER_FROM_TOKEN_AUTHENTICATE: { // if(resultCode == RESULT_OK){ fetchAuthToken(lastCallbackObjectName); // } else { // clearAccount(); // UnityPlayer.UnitySendMessage(lastCallbackObjectName, CALLBACK_METHOD_DRIVE_AUTH_CANCELED, "" + resultCode); // } break; } case REQUEST_CODE_RECOVER_FROM_DRIVE_UPLOAD_ERROR: { if (resultCode == RESULT_OK) { // user fixed the authentication problem try upload again uploadFile(lastDriveFolderName, lastDriveFileName, lastLocalPath, lastCallbackObjectName); } else { // this happens when the user deny's the authorization // we will clear the auth data in-case they wanted to switch accounts on the next try clearAccount(); UnityPlayer.UnitySendMessage(lastCallbackObjectName, CALLBACK_METHOD_DRIVE_AUTH_CANCELED, "" + resultCode); } break; } default: super.onActivityResult(requestCode, resultCode, data); } }
From source file:com.cerema.cloud2.files.InstantUploadBroadcastReceiver.java
private void handleConnectivityAction(Context context, Intent intent) { if (!instantPictureUploadEnabled(context)) { Log_OC.d(TAG, "Instant upload disabled, don't upload anything"); return;/* w ww . j a v a 2 s.co m*/ } if (instantPictureUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context)) { Account account = AccountUtils.getCurrentOwnCloudAccount(context); if (account == null) { Log_OC.w(TAG, "No account found for instant upload, aborting"); return; } Intent i = new Intent(context, FileUploader.class); i.putExtra(FileUploader.KEY_ACCOUNT, account); i.putExtra(FileUploader.KEY_CANCEL_ALL, true); context.startService(i); } if (!intent.hasExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY) && isOnline(context) && (!instantPictureUploadViaWiFiOnly(context) || (instantPictureUploadViaWiFiOnly(context) == isConnectedViaWiFi(context) == true))) { DbHandler db = new DbHandler(context); Cursor c = db.getAwaitingFiles(); if (c.moveToFirst()) { do { if (instantPictureUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context)) { break; } String account_name = c.getString(c.getColumnIndex("account")); String file_path = c.getString(c.getColumnIndex("path")); File f = new File(file_path); if (f.exists()) { Account account = new Account(account_name, MainApp.getAccountType()); String mimeType = null; try { mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension( f.getName().substring(f.getName().lastIndexOf('.') + 1)); } catch (Throwable e) { Log_OC.e(TAG, "Trying to find out MIME type of a file without extension: " + f.getName()); } if (mimeType == null) mimeType = "application/octet-stream"; Intent i = new Intent(context, FileUploader.class); i.putExtra(FileUploader.KEY_ACCOUNT, account); i.putExtra(FileUploader.KEY_LOCAL_FILE, file_path); i.putExtra(FileUploader.KEY_REMOTE_FILE, FileStorageUtils.getInstantUploadFilePath(context, f.getName())); i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE); i.putExtra(FileUploader.KEY_INSTANT_UPLOAD, true); // instant upload behaviour i = addInstantUploadBehaviour(i, context); context.startService(i); } else { Log_OC.w(TAG, "Instant upload file " + f.getAbsolutePath() + " dont exist anymore"); } } while (c.moveToNext()); } c.close(); db.close(); } }
From source file:io.flutter.plugins.googlesignin.GoogleSignInPlugin.java
/** * Gets an OAuth access token with the scopes that were specified during {@link * #init(response,List<String>) initialization} for the user with the specified email * address./* w ww .ja v a 2 s . c om*/ */ private void getToken(Response response, final String email) { if (email == null) { response.error(ERROR_REASON_EXCEPTION, "Email is null", null); return; } if (checkAndSetPendingOperation(METHOD_GET_TOKEN, response)) { return; } Callable<String> getTokenTask = new Callable<String>() { @Override public String call() throws Exception { Account account = new Account(email, "com.google"); String scopesStr = "oauth2:" + Joiner.on(' ').join(requestedScopes); return GoogleAuthUtil.getToken(activity.getApplication(), account, scopesStr); } }; backgroundTaskRunner.runInBackground(getTokenTask, new BackgroundTaskRunner.Callback<String>() { @Override public void run(Future<String> tokenFuture) { try { finishWithSuccess(tokenFuture.get()); } catch (ExecutionException e) { Log.e(TAG, "Exception getting access token", e); finishWithError(ERROR_REASON_EXCEPTION, e.getCause().getMessage()); } catch (InterruptedException e) { finishWithError(ERROR_REASON_EXCEPTION, e.getMessage()); } } }); }
From source file:com.ntsync.android.sync.activities.ShopActivity.java
public void onVerifyComplete(PayPalConfirmationResult result) { boolean removePayment = false; AccountManager acm = AccountManager.get(this); Account account = new Account(accountName, Constants.ACCOUNT_TYPE); if (result != null) { LogHelper.logI(TAG, "Payment verified. Result:" + result); switch (result) { case SUCCESS: removePayment = true;/*from w w w.jav a 2s .c o m*/ onPaymentSuccess(account); break; case INVALID_PRICE: removePayment = true; MessageDialog.show(R.string.shop_activity_invalidprice, this); break; case INVALID_SYNTAX: removePayment = true; MessageDialog.show(R.string.shop_activity_invalidsyntax, this); break; case CANCELED: removePayment = true; MessageDialog.show(R.string.shop_activity_paymentcanceled, this); break; case NOT_APPROVED: case SALE_NOT_COMPLETED: MessageDialog.show(R.string.shop_activity_notapproved, this); break; case VERIFIER_ERROR: MessageDialog.showAndClose(R.string.shop_activity_verifiererror, this); break; case ALREADY_PROCESSED: removePayment = true; MessageDialog.show(R.string.shop_activity_paymentalreadyused, this); break; case UNKNOWN_PAYMENT: MessageDialog.showAndClose(R.string.shop_activity_verificationfailed, this); // Try to validate it one more time, later. break; case AUTHENTICATION_FAILED: MessageDialog.showAndClose(R.string.shop_activity_authfailed, this); break; case NETWORK_ERROR: MessageDialog.showAndClose(R.string.shop_activity_networkerror, this); break; default: removePayment = true; LogHelper.logE(TAG, "Unknown PaymentVerificationResult:" + result, null); // Unknown State MessageDialog.showAndClose(R.string.shop_activity_verificationfailed, this); break; } } else { finish(); } if (removePayment) { SyncUtils.savePayment(account, acm, null, null); } SyncUtils.stopPaymentVerification(); }
From source file:eu.trentorise.smartcampus.ac.authenticator.AMSCAccessProvider.java
@Override public UserData readUserData(Context ctx, String inAuthority) { AccountManager am = AccountManager.get(ctx); Account account = new Account(Constants.getAccountName(ctx), Constants.getAccountType(ctx)); // final String authority = inAuthority == null ? Constants.AUTHORITY_DEFAULT : inAuthority; // String token = am.peekAuthToken(account, authority); // if (token == null) return null; String userDataString = am.getUserData(account, AccountManager.KEY_USERDATA); if (userDataString == null) return null; try {/*from w w w. j a v a 2s. c o m*/ return UserData.valueOf(new JSONObject(userDataString)); } catch (JSONException e) { return null; } }
From source file:com.clearcenter.mobile_demo.mdAuthenticatorActivity.java
private void finishConfirmCredentials(boolean result, String authToken) { Log.i(TAG, "finishConfirmCredentials()"); final Account account = new Account(nickname, mdConstants.ACCOUNT_TYPE); if (result)/*ww w . j ava 2 s.co m*/ account_manager.setPassword(account, authToken); final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_BOOLEAN_RESULT, result); setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); }
From source file:io.v.android.apps.account_manager.AccountActivity.java
private void enforceAccountExists() { if (AccountManager.get(this).getAccountsByType(Constants.ACCOUNT_TYPE).length <= 0) { String name = "Vanadium"; Account account = new Account(name, getResources().getString(R.string.authenticator_account_type)); AccountManager am = AccountManager.get(this); am.addAccountExplicitly(account, null, null); }//from w w w .ja v a 2 s.co m }
From source file:com.quarterfull.newsAndroid.NewsReaderListActivity.java
/** * Check if the account is in the Android Account Manager. If not it will be added automatically *//* w w w . j a v a 2 s. com*/ private void initAccountManager() { AccountManager mAccountManager = AccountManager.get(this); boolean isAccountThere = false; Account[] accounts = mAccountManager.getAccounts(); for (Account account : accounts) { if (account.type.intern().equals(AccountGeneral.ACCOUNT_TYPE)) { isAccountThere = true; } } //If the account is not in the Android Account Manager if (!isAccountThere) { //Then add the new account Account account = new Account(getString(R.string.app_name), AccountGeneral.ACCOUNT_TYPE); mAccountManager.addAccountExplicitly(account, "", new Bundle()); SyncIntervalSelectorActivity.SetAccountSyncInterval(this); } }
From source file:com.owncloud.android.ui.activity.ManageAccountsActivity.java
/** * Callback executed after the {@link AccountManager} removed an account * * @param future Result of the removal; future.getResult() is true if account was removed correctly. */// w w w .ja v a 2 s. c om @Override public void run(AccountManagerFuture<Boolean> future) { if (future != null && future.isDone()) { Account account = new Account(mAccountBeingRemoved, MainApp.getAccountType()); if (!AccountUtils.exists(account.name, MainApp.getAppContext())) { // Cancel transfers of the removed account if (mUploaderBinder != null) { mUploaderBinder.cancel(account); } if (mDownloaderBinder != null) { mDownloaderBinder.cancel(account); } } mAccountListAdapter = new AccountListAdapter(this, getAccountListItems(), mTintedCheck); mListView.setAdapter(mAccountListAdapter); AccountManager am = AccountManager.get(this); if (am.getAccountsByType(MainApp.getAccountType()).length == 0) { // Show create account screen if there isn't any account am.addAccount(MainApp.getAccountType(), null, null, null, this, null, null); } else { // at least one account left if (AccountUtils.getCurrentOwnCloudAccount(this) == null) { // current account was removed - set another as current String accountName = ""; Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType()); if (accounts.length != 0) { accountName = accounts[0].name; } AccountUtils.setCurrentOwnCloudAccount(this, accountName); } } } }