List of usage examples for android.provider ContactsContract AUTHORITY
String AUTHORITY
To view the source code for android.provider ContactsContract AUTHORITY.
Click Source Link
From source file:Main.java
/** * @return {@code uri} as-is if the authority is of contacts provider. Otherwise * or {@code uri} is null, return null otherwise */// w w w. ja va 2s . c om public static Uri nullForNonContactsUri(Uri uri) { if (uri == null) { return null; } return ContactsContract.AUTHORITY.equals(uri.getAuthority()) ? uri : null; }
From source file:Main.java
/** * When adding account// w ww. j ava 2 s . co m * open the same UI screen for user to choose account */ public static Intent getIntentForAddingAccount() { final Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[] { ContactsContract.AUTHORITY }); return intent; }
From source file:Main.java
/** * Transforms the given Uri and returns a Lookup-Uri that represents the contact. * For legacy contacts, a raw-contact lookup is performed. An {@link IllegalArgumentException} * can be thrown if the URI is null or the authority is not recognized. * * Do not call from the UI thread./*from w w w . j a v a2s. c om*/ */ @SuppressWarnings("deprecation") public static Uri ensureIsContactUri(final ContentResolver resolver, final Uri uri) throws IllegalArgumentException { if (uri == null) throw new IllegalArgumentException("uri must not be null"); final String authority = uri.getAuthority(); // Current Style Uri? if (ContactsContract.AUTHORITY.equals(authority)) { final String type = resolver.getType(uri); // Contact-Uri? Good, return it if (ContactsContract.Contacts.CONTENT_ITEM_TYPE.equals(type)) { return uri; } // RawContact-Uri? Transform it to ContactUri if (RawContacts.CONTENT_ITEM_TYPE.equals(type)) { final long rawContactId = ContentUris.parseId(uri); return RawContacts.getContactLookupUri(resolver, ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); } // Anything else? We don't know what this is throw new IllegalArgumentException("uri format is unknown"); } // Legacy Style? Convert to RawContact final String OBSOLETE_AUTHORITY = Contacts.AUTHORITY; if (OBSOLETE_AUTHORITY.equals(authority)) { // Legacy Format. Convert to RawContact-Uri and then lookup the contact final long rawContactId = ContentUris.parseId(uri); return RawContacts.getContactLookupUri(resolver, ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); } throw new IllegalArgumentException("uri authority is unknown"); }
From source file:com.ntsync.android.sync.shared.SyncUtils.java
/** * Check if a Sync is active//from w ww. j av a2 s . com * * @param accountName * @return true if a Sync is active with the current Account Name */ public static boolean isSyncActive(String accountName) { Account account = new Account(accountName, Constants.ACCOUNT_TYPE); return ContentResolver.isSyncActive(account, ContactsContract.AUTHORITY); }
From source file:mobisocial.musubi.ui.ViewProfileActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tabbed); Intent intent = getIntent();//www . ja v a 2 s . c o m Long id = null; // intent from address book Intent is = getIntent(); Uri data = getIntent().getData(); String type = getIntent().getType(); if (data != null) { if (type != null && type.equals(MusubiContentProvider.getType(Provided.IDENTITIES_ID))) { id = ContentUris.parseId(data); } else if (data.getAuthority().equals(ContactsContract.AUTHORITY)) { // intent sent from address book have null type long rawId = ContentUris.parseId(data); id = getMusubiId(rawId); } } if (id == null) { id = intent.getLongExtra(PROFILE_ID, -1); } setTitle("Relationships"); mLabels.add("Profile"); mFragments.add(ViewProfileFragment.newInstance(id)); SQLiteOpenHelper helper = App.getDatabaseSource(this); IdentitiesManager im = new IdentitiesManager(helper); MIdentity identity = im.getIdentityForId(id); if (identity == null) { UsageMetrics.getUsageMetrics(this) .report(new Throwable("Invalid identity " + id + " passed tp ViewProfileActivity")); finish(); return; } FeedManager fm = new FeedManager(helper); mFeedIds = fm.getFeedsForIdentityId(id); setTitle(identity.name_); if (!identity.owned_) { mLabels.add("Conversations"); Bundle args = new Bundle(); args.putLong(ConversationsFragment.ARG_IDENTITY_ID, identity.id_); ConversationsFragment f = new ConversationsFragment(); f.setArguments(args); mFragments.add(f); } else { setTitle("Your profile"); } PagerAdapter adapter = new ViewFragmentAdapter(getSupportFragmentManager(), mFragments, mLabels); mViewPager = (ViewPager) findViewById(R.id.feed_pager); mViewPager.setAdapter(adapter); //Bind the tab indicator to the adapter TabPageIndicator tabIndicator = (TabPageIndicator) findViewById(R.id.feed_titles); tabIndicator.setViewPager(mViewPager); }
From source file:org.xwalk.runtime.extension.api.contacts.Contacts.java
@Override public void onMessage(int instanceID, String message) { if (message.isEmpty()) return;/*from ww w. j av a 2 s. c o m*/ try { JSONObject jsonInput = new JSONObject(message); String cmd = jsonInput.getString("cmd"); if (cmd.equals("addEventListener")) { mObserver.startListening(); return; } JSONObject jsonOutput = new JSONObject(); jsonOutput.put("_promise_id", jsonInput.getString("_promise_id")); if (cmd.equals("save")) { ContactSaver saver = new ContactSaver(mResolver); jsonOutput.put("data", saver.save(jsonInput.getString("contact"))); } else if (cmd.equals("find")) { ContactFinder finder = new ContactFinder(mResolver); String options = jsonInput.has("options") ? jsonInput.getString("options") : null; JSONArray results = finder.find(options); jsonOutput.put("data", results); } else if (cmd.equals("remove")) { ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); String[] args = new String[] { jsonInput.getString("contactId") }; ops.add(ContentProviderOperation.newDelete(RawContacts.CONTENT_URI) .withSelection(RawContacts.CONTACT_ID + "=?", args).build()); try { mResolver.applyBatch(ContactsContract.AUTHORITY, ops); } catch (Exception e) { if (e instanceof RemoteException || e instanceof OperationApplicationException || e instanceof SecurityException) { Log.e(TAG, "onMessage - Failed to apply batch: " + e.toString()); return; } else { throw new RuntimeException(e); } } } else if (cmd.equals("clear")) { handleClear(); } else { Log.e(TAG, "Unexpected message received: " + message); return; } this.postMessage(instanceID, jsonOutput.toString()); } catch (JSONException e) { Log.e(TAG, e.toString()); } }
From source file:com.ntsync.android.sync.activities.AccountStatisticListLoader.java
@Override public List<AccountStatistic> loadInBackground() { Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE); List<AccountStatistic> statList = new ArrayList<AccountStatistic>(); for (Account account : accounts) { String username = account.name; int contactCount = -1; int contactGroupCount = -1; Context ctx = getContext(); AccountSyncResult syncResult = SyncUtils.getSyncResult(accountManager, account); Date lastSync = syncResult != null ? syncResult.getLastSyncTime() : null; Date nextSync = null;//from w ww.j a va 2s. c o m boolean autoSyncEnabled = ContentResolver.getMasterSyncAutomatically() && ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY); if (autoSyncEnabled) { List<PeriodicSync> syncs = ContentResolver.getPeriodicSyncs(account, ContactsContract.AUTHORITY); long nextSyncRef = lastSync != null ? lastSync.getTime() : System.currentTimeMillis(); for (PeriodicSync sync : syncs) { long nextTime = nextSyncRef + sync.period * 1000; if (nextSync == null || nextTime < nextSync.getTime()) { nextSync = new Date(nextTime); } } } boolean autoSync = ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY); // Get Restrictions Restrictions restr = SyncUtils.getRestrictions(account, accountManager); if (restr == null) { try { String authtoken = NetworkUtilities.blockingGetAuthToken(accountManager, account, null); restr = NetworkUtilities.getRestrictions(getContext(), account, authtoken, accountManager); } catch (OperationCanceledException e) { Log.i(TAG, "Restriction loading canceled from user", e); } catch (AuthenticatorException e) { Log.w(TAG, "Authenticator failed", e); } catch (AuthenticationException e) { Log.i(TAG, "Authentification failed", e); } catch (NetworkErrorException e) { Log.i(TAG, "Loading Restrictions failed", e); } catch (ServerException e) { Log.i(TAG, "Loading Restrictions failed", e); } } contactCount = ContactManager.getContactCount(ctx, account); contactGroupCount = ContactManager.getContactGroupCount(ctx, account); statList.add(new AccountStatistic(username, contactCount, contactGroupCount, restr, syncResult, nextSync, autoSync)); } return statList; }
From source file:at.bitfire.davdroid.syncadapter.AccountDetailsFragment.java
void addAccount() { ServerInfo serverInfo = (ServerInfo) getArguments().getSerializable(KEY_SERVER_INFO); String accountName = editAccountName.getText().toString(); AccountManager accountManager = AccountManager.get(getActivity()); Account account = new Account(accountName, Constants.ACCOUNT_TYPE); Bundle userData = new Bundle(); userData.putString(Constants.ACCOUNT_KEY_BASE_URL, serverInfo.getBaseURL()); userData.putString(Constants.ACCOUNT_KEY_USERNAME, serverInfo.getUserName()); userData.putString(Constants.ACCOUNT_KEY_AUTH_PREEMPTIVE, Boolean.toString(serverInfo.isAuthPreemptive())); boolean syncContacts = false; for (ServerInfo.ResourceInfo addressBook : serverInfo.getAddressBooks()) if (addressBook.isEnabled()) { userData.putString(Constants.ACCOUNT_KEY_ADDRESSBOOK_PATH, addressBook.getPath()); ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1); syncContacts = true;//w w w .ja v a 2 s. co m continue; } if (syncContacts) { ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1); ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); } else ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 0); if (accountManager.addAccountExplicitly(account, serverInfo.getPassword(), userData)) { // account created, now create calendars ContentResolver.setIsSyncable(account, "com.android.calendar", 0); getActivity().finish(); } else Toast.makeText(getActivity(), "Couldn't create account (account with this name already existing?)", Toast.LENGTH_LONG).show(); }
From source file:com.germainz.identiconizer.services.IdenticonRemovalService.java
private void processPhotos() { Cursor cursor = getIdenticonPhotos(); final int totalPhotos = cursor.getCount(); int currentPhoto = 1; while (cursor.moveToNext()) { final long contactId = cursor.getLong(0); updateNotification(getString(R.string.identicons_remove_service_running_title), String.format( getString(R.string.identicons_remove_service_contact_summary), currentPhoto++, totalPhotos)); byte[] data = cursor.getBlob(1); if (IdenticonUtils.isIdenticon(data)) removeIdenticon(contactId);/*from ww w. j a va2 s .c o m*/ } cursor.close(); if (!mOps.isEmpty()) { updateNotification(getString(R.string.identicons_remove_service_running_title), getString(R.string.identicons_remove_service_contact_summary_finishing)); try { // Perform operations in batches of 100, to avoid TransactionTooLargeExceptions for (int i = 0, j = mOps.size(); i < j; i += 100) getContentResolver().applyBatch(ContactsContract.AUTHORITY, new ArrayList<ContentProviderOperation>(mOps.subList(i, i + Math.min(100, j - i)))); } catch (RemoteException | OperationApplicationException e) { Log.e(TAG, "Unable to apply batch", e); } } }
From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setFullScreenDialogClose(new View.OnClickListener() { @Override//from www . j a v a2 s .co m public void onClick(View v) { finish(); } }); mProviderHelper = new ProviderHelper(this); mViewPager = (ViewPager) findViewById(R.id.pager); mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tab_layout); mDataUri = getIntent().getData(); if (mDataUri == null) { Log.e(Constants.TAG, "Data missing. Should be uri of key!"); finish(); return; } if (mDataUri.getHost().equals(ContactsContract.AUTHORITY)) { mDataUri = new ContactHelper(this).dataUriFromContactUri(mDataUri); if (mDataUri == null) { Log.e(Constants.TAG, "Contact Data missing. Should be uri of key!"); Toast.makeText(this, R.string.error_contacts_key_id_missing, Toast.LENGTH_LONG).show(); finish(); return; } } // Prepare the loaders. Either re-connect with an existing ones, // or start new ones. getSupportLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this); initTabs(mDataUri); }