List of usage examples for android.content Context ACCOUNT_SERVICE
String ACCOUNT_SERVICE
To view the source code for android.content Context ACCOUNT_SERVICE.
Click Source Link
From source file:com.triarc.sync.SyncAdapter.java
/** * Constructor. Obtains handle to content resolver for later use. *//*from w w w. j a va2s . c o m*/ public SyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); this.mAccountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); format.setTimeZone(TimeZone.getTimeZone("UTC")); }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.ChannelService.java
private static void storeRegistrationId(Context context, String regId, String channelId) { AccountManager am = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); Account ac = AccountUtils.getAccount(context, true); am.setUserData(ac, JsonKeys.REGISTER_ID, regId); am.setUserData(ac, JsonKeys.CHANNEL_ID, channelId); }
From source file:com.android.managedprovisioning.ProfileOwnerProvisioningService.java
@Override public void onCreate() { super.onCreate(); mIpm = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE); mUserManager = (UserManager) getSystemService(Context.USER_SERVICE); runnerTask = new RunnerTask(); }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.ChannelService.java
public static String getChannelId(Context context) { AccountManager am = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); Account ac = AccountUtils.getAccount(context, false); if (ac == null) { log.warn("Account is null. Channel id can not be get"); return null; }/*from w w w. j a v a 2s .c o m*/ String channelId = am.getUserData(ac, JsonKeys.CHANNEL_ID); if ((channelId == null || channelId.length() == 0)) { return null; } else { return channelId; } }
From source file:net.heroicefforts.viable.android.rep.it.GIssueTrackerRepository.java
public GIssueTrackerRepository(String appName, Activity act, Bundle metaData) throws CreateException { this.appName = appName; this.act = act; this.projectName = metaData.getString(PARAM_PROJECT_NAME); if (projectName == null) throw new CreateException("No '" + "viable-project-name" + "' meta-data field defined for application. Google Isusue Tracker Repository cannot be constructed."); this.description = metaData.getString(PARAM_PROJECT_DESC); this.lead = metaData.getString(PARAM_PROJECT_ADMIN); String versionStr = metaData.getString(PARAM_VERSIONS); if (versionStr != null) { String[] versions = versionStr.split("[ ]*,[ ]*"); for (String version : versions) this.versions.add(new VersionDetail(version)); }/* w w w. j a v a 2 s . co m*/ try { host = new ProjectHostingService(); String token = Authenticate.authenticate(act, GCLAccountAuthenticator.TOKEN_TYPE_ISSUE_TRACKER); if (token != null) host.setAuthSubToken(token); else { //TODO add popup. AccountManager acct = (AccountManager) act.getSystemService(Context.ACCOUNT_SERVICE); if (Config.LOGD) Log.d(TAG, "Requesting account creation."); acct.addAccount(GCLAccountAuthenticator.ACCT_TYPE, "code", null, null, act, callback, null); } } catch (AuthenticatorException e) { throw new CreateException( "Exception authenticating Google account for Issue Tracker repository access."); } catch (Exception e) { throw new CreateException("Exception creating Google Issue Tracker repository.", e); } }
From source file:com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter.java
/** * Helper method to get the fake account to be used with SyncAdapter, or make a new one if the * fake account doesn't exist yet./*from ww w . j a v a 2 s . c o m*/ * * @param context * The context used to access the account service * @return a fake account. */ public static Account getSyncAccount(Context context) { // Get an instance of the Android account manager AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); // Create the account type and default account Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.sync_account_type)); // If the password doesn't exist, the account doesn't exist if (null == accountManager.getPassword(newAccount)) { // Add the account and account type, no password or user data // If successful, return the Account object, otherwise report an error. if (!accountManager.addAccountExplicitly(newAccount, "", null)) { return null; } // If you don't set android:syncable="true" in your <provider> element in the manifest, // then call context.setIsSyncable(account, AUTHORITY, 1) here. onAccountCreated(newAccount, context); } return newAccount; }
From source file:com.irccloud.android.activity.LoginActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= 21) { Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), cloud, 0xff0b2e60));/*from www .j av a 2 s. c o m*/ cloud.recycle(); } requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); setContentView(R.layout.activity_login); loading = findViewById(R.id.loading); connecting = findViewById(R.id.connecting); connectingMsg = (TextView) findViewById(R.id.connectingMsg); progressBar = (ProgressBar) findViewById(R.id.connectingProgress); loginHint = (LinearLayout) findViewById(R.id.loginHint); signupHint = (LinearLayout) findViewById(R.id.signupHint); hostHint = (TextView) findViewById(R.id.hostHint); login = findViewById(R.id.login); name = (EditText) findViewById(R.id.name); if (savedInstanceState != null && savedInstanceState.containsKey("name")) name.setText(savedInstanceState.getString("name")); email = (AutoCompleteTextView) findViewById(R.id.email); if (BuildConfig.ENTERPRISE) email.setHint(R.string.email_enterprise); ArrayList<String> accounts = new ArrayList<String>(); AccountManager am = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE); for (Account a : am.getAccounts()) { if (a.name.contains("@") && !accounts.contains(a.name)) accounts.add(a.name); } if (accounts.size() > 0) email.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, accounts.toArray(new String[accounts.size()]))); if (savedInstanceState != null && savedInstanceState.containsKey("email")) email.setText(savedInstanceState.getString("email")); password = (EditText) findViewById(R.id.password); password.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { new LoginTask().execute((Void) null); return true; } return false; } }); if (savedInstanceState != null && savedInstanceState.containsKey("password")) password.setText(savedInstanceState.getString("password")); host = (EditText) findViewById(R.id.host); if (BuildConfig.ENTERPRISE) host.setText(NetworkConnection.IRCCLOUD_HOST); else host.setVisibility(View.GONE); host.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { new LoginTask().execute((Void) null); return true; } return false; } }); if (savedInstanceState != null && savedInstanceState.containsKey("host")) host.setText(savedInstanceState.getString("host")); else host.setText(getSharedPreferences("prefs", 0).getString("host", BuildConfig.HOST)); if (host.getText().toString().equals("api.irccloud.com") || host.getText().toString().equals("www.irccloud.com")) host.setText(""); loginBtn = (Button) findViewById(R.id.loginBtn); loginBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new LoginTask().execute((Void) null); } }); loginBtn.setFocusable(true); loginBtn.requestFocus(); sendAccessLinkBtn = (Button) findViewById(R.id.sendAccessLink); sendAccessLinkBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { new ResetPasswordTask().execute((Void) null); } }); nextBtn = (Button) findViewById(R.id.nextBtn); nextBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (host.getText().length() > 0) { NetworkConnection.IRCCLOUD_HOST = host.getText().toString(); trimHost(); new EnterpriseConfigTask().execute((Void) null); } } }); TOS = (TextView) findViewById(R.id.TOS); TOS.setMovementMethod(new LinkMovementMethod()); forgotPassword = (TextView) findViewById(R.id.forgotPassword); forgotPassword.setOnClickListener(forgotPasswordClickListener); enterpriseLearnMore = (TextView) findViewById(R.id.enterpriseLearnMore); enterpriseLearnMore.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (isPackageInstalled("com.irccloud.android", LoginActivity.this)) { startActivity(getPackageManager().getLaunchIntentForPackage("com.irccloud.android")); } else { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.irccloud.android"))); } catch (Exception e) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.irccloud.android"))); } } } private boolean isPackageInstalled(String packagename, Context context) { PackageManager pm = context.getPackageManager(); try { pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES); return true; } catch (NameNotFoundException e) { return false; } } }); enterpriseHint = (LinearLayout) findViewById(R.id.enterpriseHint); EnterYourEmail = (TextView) findViewById(R.id.enterYourEmail); signupHint.setOnClickListener(signupHintClickListener); loginHint.setOnClickListener(loginHintClickListener); signupBtn = (Button) findViewById(R.id.signupBtn); signupBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { new LoginTask().execute((Void) null); } }); TextView version = (TextView) findViewById(R.id.version); try { version.setText("Version " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName); } catch (NameNotFoundException e) { version.setVisibility(View.GONE); } Typeface LatoRegular = Typeface.createFromAsset(getAssets(), "Lato-Regular.ttf"); Typeface LatoLightItalic = Typeface.createFromAsset(getAssets(), "Lato-LightItalic.ttf"); for (int i = 0; i < signupHint.getChildCount(); i++) { View v = signupHint.getChildAt(i); if (v instanceof TextView) { ((TextView) v).setTypeface(LatoRegular); } } for (int i = 0; i < loginHint.getChildCount(); i++) { View v = loginHint.getChildAt(i); if (v instanceof TextView) { ((TextView) v).setTypeface(LatoRegular); } } LinearLayout IRCCloud = (LinearLayout) findViewById(R.id.IRCCloud); for (int i = 0; i < IRCCloud.getChildCount(); i++) { View v = IRCCloud.getChildAt(i); if (v instanceof TextView) { ((TextView) v).setTypeface(LatoRegular); } } notAProblem = (LinearLayout) findViewById(R.id.notAProblem); for (int i = 0; i < notAProblem.getChildCount(); i++) { View v = notAProblem.getChildAt(i); if (v instanceof TextView) { ((TextView) v).setTypeface((i == 0) ? LatoRegular : LatoLightItalic); } } loginSignupHint = (LinearLayout) findViewById(R.id.loginSignupHint); for (int i = 0; i < loginSignupHint.getChildCount(); i++) { View v = loginSignupHint.getChildAt(i); if (v instanceof TextView) { ((TextView) v).setTypeface(LatoRegular); ((TextView) v).setOnClickListener((i == 0) ? loginHintClickListener : signupHintClickListener); } } name.setTypeface(LatoRegular); email.setTypeface(LatoRegular); password.setTypeface(LatoRegular); host.setTypeface(LatoRegular); loginBtn.setTypeface(LatoRegular); signupBtn.setTypeface(LatoRegular); TOS.setTypeface(LatoRegular); EnterYourEmail.setTypeface(LatoRegular); hostHint.setTypeface(LatoLightItalic); if (BuildConfig.ENTERPRISE) { name.setVisibility(View.GONE); email.setVisibility(View.GONE); password.setVisibility(View.GONE); loginBtn.setVisibility(View.GONE); signupBtn.setVisibility(View.GONE); TOS.setVisibility(View.GONE); signupHint.setVisibility(View.GONE); loginHint.setVisibility(View.GONE); forgotPassword.setVisibility(View.GONE); loginSignupHint.setVisibility(View.GONE); EnterYourEmail.setVisibility(View.GONE); sendAccessLinkBtn.setVisibility(View.GONE); notAProblem.setVisibility(View.GONE); enterpriseLearnMore.setVisibility(View.VISIBLE); enterpriseHint.setVisibility(View.VISIBLE); host.setVisibility(View.VISIBLE); nextBtn.setVisibility(View.VISIBLE); hostHint.setVisibility(View.VISIBLE); host.requestFocus(); } if (savedInstanceState != null && savedInstanceState.containsKey("signup") && savedInstanceState.getBoolean("signup")) { signupHintClickListener.onClick(null); } if (savedInstanceState != null && savedInstanceState.containsKey("login") && savedInstanceState.getBoolean("login")) { loginHintClickListener.onClick(null); } if (savedInstanceState != null && savedInstanceState.containsKey("forgotPassword") && savedInstanceState.getBoolean("forgotPassword")) { forgotPasswordClickListener.onClick(null); } mResolvingError = savedInstanceState != null && savedInstanceState.getBoolean("resolving_error", false); mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Auth.CREDENTIALS_API) .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build(); }
From source file:com.cerema.cloud2.ui.activity.Uploader.java
@Override protected void setAccount(Account account, boolean savedAccount) { if (somethingToUpload()) { mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE); Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType()); if (accounts.length == 0) { Log_OC.i(TAG, "No ownCloud account is available"); showDialog(DIALOG_NO_ACCOUNT); } else if (accounts.length > 1 && !mAccountSelected && !mAccountSelectionShowing) { Log_OC.i(TAG, "More than one ownCloud is available"); showDialog(DIALOG_MULTIPLE_ACCOUNT); mAccountSelectionShowing = true; } else {// w w w.ja v a2 s.c o m if (!savedAccount) { setAccount(accounts[0]); } } } else { showDialog(DIALOG_NO_STREAM); } super.setAccount(account, savedAccount); }
From source file:io.v.syncslides.SignInActivity.java
private void fetchUserProfile() { AccountManager manager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE); Account[] accounts = manager.getAccountsByType("com.google"); Account account = null;/*from w w w. j a va 2 s. co m*/ for (int i = 0; i < accounts.length; i++) { if (accounts[i].name.equals(mAccountName)) { account = accounts[i]; break; } } if (account == null) { Log.e(TAG, "Couldn't find Google account with name: " + mAccountName); pickAccount(); return; } manager.getAuthToken(account, OAUTH_SCOPE, new Bundle(), false, new OnTokenAcquired(), new Handler(msg -> { Log.e(TAG, "Error getting auth token: " + msg.toString()); fetchUserProfileDone(null); return true; })); }
From source file:org.pixmob.feedme.ui.EntriesFragment.java
private void authenticateAccount(String accountName) { Log.i(TAG, "Authenticating account: " + accountName); final Activity a = getActivity(); final AccountManager am = (AccountManager) a.getSystemService(Context.ACCOUNT_SERVICE); final Account account = new Account(accountName, GOOGLE_ACCOUNT); am.getAuthToken(account, "reader", null, a, new AccountManagerCallback<Bundle>() { @Override//from w ww . ja v a2 s .c o m public void run(AccountManagerFuture<Bundle> resultContainer) { String authToken = null; final Bundle result; try { result = resultContainer.getResult(); authToken = result.getString(AccountManager.KEY_AUTHTOKEN); } catch (IOException e) { Log.w(TAG, "I/O error while authenticating account " + account.name, e); } catch (OperationCanceledException e) { Log.w(TAG, "Authentication was canceled for account " + account.name, e); } catch (AuthenticatorException e) { Log.w(TAG, "Authentication failed for account " + account.name, e); } if (authToken == null) { Toast.makeText(a, a.getString(R.string.authentication_failed), Toast.LENGTH_SHORT).show(); } else { Log.i(TAG, "Authentication done"); onAuthenticationDone(account.name, authToken); } } }, null); }