Java Code Examples for com.android.contacts.util.ContactLoaderUtils

Following code examples demonstrate how to use com.android.contacts.util.ContactLoaderUtilsfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use com.android.contacts.util.ContactLoaderUtilsand various code implementation of this class.

        protected Uri doInBackground(Void... args) {
            Cursor cursor = null;
            try {
                final ContentResolver resolver = getContext().getContentResolver();
                final Uri uriCurrentFormat = ContactLoaderUtils.ensureIsContactUri(resolver, mUri);
                cursor = resolver.query(uriCurrentFormat,
                        new String[] { Contacts._ID, Contacts.LOOKUP_KEY }, null, null, null);

                if (cursor != null && cursor.moveToFirst()) {
                    final long contactId = cursor.getLong(0);
                    final String lookupKey = cursor.getString(1);
                    if (contactId != 0 && !TextUtils.isEmpty(lookupKey)) {
                        return Contacts.getLookupUri(contactId, lookupKey);
                    }
                }

                Log.e(TAG, "Error: No contact ID or lookup key for contact " + mUri);
                return null;
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        } 


    protected Uri getProfileLookupUri() {
        Cursor cursor = getContentResolver().query(Profile.CONTENT_URI, new String[]{"_id", "lookup"}, null, null, null);
        if (cursor != null) {
            try {
                if (cursor.moveToFirst()) {
                    this.profileLookupUri = Contacts.getLookupUri(cursor.getLong(0), cursor.getString(1));
                    this.profileLookupUri = ContactLoaderUtils.ensureIsContactUri(getContentResolver(), this.profileLookupUri);
                    if (cursor != null) {
                        cursor.close();
                    }
                    return this.profileLookupUri;
                }
            } catch (IllegalArgumentException e) {
                Log.e("IceMyInfoBaseActivity", e.getMessage());
                if (cursor != null) {
                    cursor.close();
                }
            } catch (Throwable th) {
                if (cursor != null) {
                    cursor.close();
                }
            }
        }
        Uri uri = this.profileLookupUri;
        if (cursor != null) {
            cursor.close();
        }
        return uri;
    }