/** * Posts a message to the contributing sync adapters that have opted-in, notifying them * that the contact has just been loaded */ private void postViewNotificationToSyncAdapter() { Context context = getContext(); for (RawContact rawContact : mContact.getRawContacts()) { final long rawContactId = rawContact.getId(); if (mNotifiedRawContactIds.contains(rawContactId)) { continue; // Already notified for this raw contact. } mNotifiedRawContactIds.add(rawContactId); final AccountType accountType = rawContact.getAccountType(context); final String serviceName = accountType.getViewContactNotifyServiceClassName(); final String servicePackageName = accountType.getViewContactNotifyServicePackageName(); if (!TextUtils.isEmpty(serviceName) && !TextUtils.isEmpty(servicePackageName)) { final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); final Intent intent = new Intent(); intent.setClassName(servicePackageName, serviceName); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(uri, RawContacts.CONTENT_ITEM_TYPE); try { context.startService(intent); } catch (Exception e) { Log.e(TAG, "Error sending message to source-app", e); } } } }
/** * Return the ID of the first raw-contact in the contact data that belongs to a * contact-writable account, or -1 if no such entity exists. */ public long getFirstWritableRawContactId(final Context context) { // Directory entries are non-writable if (isDirectoryEntry()) return -1; // Iterate through raw-contacts; if we find a writable on, return its ID. for (RawContact rawContact : getRawContacts()) { AccountType accountType = rawContact.getAccountType(context); if (accountType != null && accountType.areContactsWritable()) { return rawContact.getId(); } } // No writable raw-contact was found. return -1; }