Java 类android.provider.ContactsContract.Profile 实例源码

项目:TenguChat    文件:PhoneHelper.java   
public static Uri getSelfiUri(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
            && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
        return null;
    }
    String[] mProjection = new String[]{Profile._ID, Profile.PHOTO_URI};
    Cursor mProfileCursor = context.getContentResolver().query(
            Profile.CONTENT_URI, mProjection, null, null, null);

    if (mProfileCursor == null || mProfileCursor.getCount() == 0) {
        return null;
    } else {
        mProfileCursor.moveToFirst();
        String uri = mProfileCursor.getString(1);
        mProfileCursor.close();
        if (uri == null) {
            return null;
        } else {
            return Uri.parse(uri);
        }
    }
}
项目:messengerxmpp    文件:PhoneHelper.java   
public static Uri getSefliUri(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
            && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
        return null;
    }
    String[] mProjection = new String[] { Profile._ID, Profile.PHOTO_URI };
    Cursor mProfileCursor = context.getContentResolver().query(
            Profile.CONTENT_URI, mProjection, null, null, null);

    if (mProfileCursor == null || mProfileCursor.getCount() == 0) {
        return null;
    } else {
        mProfileCursor.moveToFirst();
        String uri = mProfileCursor.getString(1);
        mProfileCursor.close();
        if (uri == null) {
            return null;
        } else {
            return Uri.parse(uri);
        }
    }
}
项目:qksms    文件:Contact.java   
/**
 * @return a Contact containing the info for the profile.
 */
private Contact getContactInfoForSelf() {
    Contact entry = new Contact(true);
    entry.mContactMethodType = CONTACT_METHOD_TYPE_SELF;

    if (Log.isLoggable(LogTag.CONTACT, Log.DEBUG)) {
        log("getContactInfoForSelf");
    }
    Cursor cursor = mContext.getContentResolver().query(
            Profile.CONTENT_URI, SELF_PROJECTION, null, null, null);
    if (cursor == null) {
        Log.w(TAG, "getContactInfoForSelf() returned NULL cursor!"
                + " contact uri used " + Profile.CONTENT_URI);
        return entry;
    }

    try {
        if (cursor.moveToFirst()) {
            fillSelfContact(entry, cursor);
        }
    } finally {
        cursor.close();
    }
    return entry;
}
项目:Pix-Art-Messenger    文件:PhoneHelper.java   
public static Uri getProfilePictureUri(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
        return null;
    }

    final String[] projection = new String[]{Profile._ID, Profile.PHOTO_URI};
    final Cursor cursor;
    try {
        cursor = context.getContentResolver().query(Profile.CONTENT_URI, projection, null, null, null);
    } catch (SecurityException e) {
        return null;
    }
    if (cursor == null) {
        return null;
    }
    final String uri = cursor.moveToFirst() ? cursor.getString(1) : null;
    cursor.close();
    return uri == null ? null : Uri.parse(uri);
}
项目:Conversations    文件:PhoneHelper.java   
public static Uri getProfilePictureUri(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
        return null;
    }
    final String[] projection = new String[]{Profile._ID, Profile.PHOTO_URI};
    final Cursor cursor;
    try {
        cursor = context.getContentResolver().query(Profile.CONTENT_URI, projection, null, null, null);
    } catch (SecurityException e) {
        return null;
    }
    if (cursor == null) {
        return null;
    }
    final String uri = cursor.moveToFirst() ? cursor.getString(1) : null;
    cursor.close();
    return uri == null ? null : Uri.parse(uri);
}
项目:sms_DualCard    文件:Contact.java   
/**
 * @return a Contact containing the info for the profile.
 */
private Contact getContactInfoForSelf() {
    Contact entry = new Contact(true);
    entry.mContactMethodType = CONTACT_METHOD_TYPE_SELF;

    if (Log.isLoggable(LogTag.CONTACT, Log.DEBUG)) {
        log("getContactInfoForSelf");
    }
    Cursor cursor = mContext.getContentResolver().query(
            Profile.CONTENT_URI, SELF_PROJECTION, null, null, null);
    if (cursor == null) {
        Log.w(TAG, "getContactInfoForSelf() returned NULL cursor!"
                + " contact uri used " + Profile.CONTENT_URI);
        return entry;
    }

    try {
        if (cursor.moveToFirst()) {
            fillSelfContact(entry, cursor);
        }
    } finally {
        cursor.close();
    }
    return entry;
}
项目:frozenchat    文件:PhoneHelper.java   
public static Uri getSefliUri(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
            && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
        return null;
    }
    String[] mProjection = new String[]{Profile._ID, Profile.PHOTO_URI};
    Cursor mProfileCursor = context.getContentResolver().query(
            Profile.CONTENT_URI, mProjection, null, null, null);

    if (mProfileCursor == null || mProfileCursor.getCount() == 0) {
        return null;
    } else {
        mProfileCursor.moveToFirst();
        String uri = mProfileCursor.getString(1);
        mProfileCursor.close();
        if (uri == null) {
            return null;
        } else {
            return Uri.parse(uri);
        }
    }
}
项目:txtr    文件:PhoneHelper.java   
public static Uri getSefliUri(Context context) {
    String[] mProjection = new String[] { Profile._ID, Profile.PHOTO_URI };
    Cursor mProfileCursor = context.getContentResolver().query(
            Profile.CONTENT_URI, mProjection, null, null, null);

    if (mProfileCursor == null || mProfileCursor.getCount() == 0) {
        return null;
    } else {
        mProfileCursor.moveToFirst();
        String uri = mProfileCursor.getString(1);
        mProfileCursor.close();
        if (uri == null) {
            return null;
        } else {
            return Uri.parse(uri);
        }
    }
}
项目:SyncChatAndroid    文件:PhoneHelper.java   
public static Uri getSefliUri(Context context) {
    String[] mProjection = new String[] { Profile._ID,
            Profile.PHOTO_THUMBNAIL_URI };
    Cursor mProfileCursor = context.getContentResolver().query(
            Profile.CONTENT_URI, mProjection, null, null, null);

    if (mProfileCursor.getCount() == 0) {
        return null;
    } else {
        mProfileCursor.moveToFirst();
        String uri = mProfileCursor.getString(1);
        if (uri == null) {
            return null;
        } else {
            return Uri.parse(uri);
        }
    }
}
项目:android-aosp-mms    文件:Contact.java   
/**
 * @return a Contact containing the info for the profile.
 */
private Contact getContactInfoForSelf() {
    Contact entry = new Contact(true);
    entry.mContactMethodType = CONTACT_METHOD_TYPE_SELF;

    if (Log.isLoggable(LogTag.CONTACT, Log.DEBUG)) {
        log("getContactInfoForSelf");
    }
    Cursor cursor = mContext.getContentResolver().query(
            Profile.CONTENT_URI, SELF_PROJECTION, null, null, null);
    if (cursor == null) {
        Log.w(TAG, "getContactInfoForSelf() returned NULL cursor!"
                + " contact uri used " + Profile.CONTENT_URI);
        return entry;
    }

    try {
        if (cursor.moveToFirst()) {
            fillSelfContact(entry, cursor);
        }
    } finally {
        cursor.close();
    }
    return entry;
}
项目:android-aosp-mms    文件:MessageListItem.java   
private void updateAvatarView(String addr, boolean isSelf) {
    Drawable avatarDrawable;
    if (isSelf || !TextUtils.isEmpty(addr)) {
        Contact contact = isSelf ? Contact.getMe(false) : Contact.get(addr, false);
        avatarDrawable = contact.getAvatar(mContext, sDefaultContactImage);

        if (isSelf) {
            mAvatar.assignContactUri(Profile.CONTENT_URI);
        } else {
            if (contact.existsInDatabase()) {
                mAvatar.assignContactUri(contact.getUri());
            } else {
                mAvatar.assignContactFromPhone(contact.getNumber(), true);
            }
        }
    } else {
        avatarDrawable = sDefaultContactImage;
    }
    mAvatar.setImageDrawable(avatarDrawable);
}
项目:qksms    文件:Contact.java   
private byte[] loadAvatarData(Contact entry) {
    byte [] data = null;

    if ((!entry.mIsMe && entry.mPersonId == 0) || entry.mAvatar != null) {
        return null;
    }

    if (Log.isLoggable(LogTag.CONTACT, Log.DEBUG)) {
        log("loadAvatarData: name=" + entry.mName + ", number=" + entry.mNumber);
    }

    // If the contact is "me", then use my local profile photo. Otherwise, build a
    // uri to get the avatar of the contact.
    Uri contactUri = entry.mIsMe ?
            Profile.CONTENT_URI :
            ContentUris.withAppendedId(Contacts.CONTENT_URI, entry.mPersonId);

    InputStream avatarDataStream = Contacts.openContactPhotoInputStream(
            mContext.getContentResolver(),
            contactUri, true);
    try {
        if (avatarDataStream != null) {
            data = new byte[avatarDataStream.available()];
            avatarDataStream.read(data, 0, data.length);
        }
    } catch (IOException ex) {
        //
    } finally {
        try {
            if (avatarDataStream != null) {
                avatarDataStream.close();
            }
        } catch (IOException e) {
        }
    }

    return data;
}
项目:sms_DualCard    文件:Contact.java   
private byte[] loadAvatarData(Contact entry) {
    byte [] data = null;

    if ((!entry.mIsMe && entry.mPersonId == 0) || entry.mAvatar != null) {
        return null;
    }

    if (Log.isLoggable(LogTag.CONTACT, Log.DEBUG)) {
        log("loadAvatarData: name=" + entry.mName + ", number=" + entry.mNumber);
    }

    // If the contact is "me", then use my local profile photo. Otherwise, build a
    // uri to get the avatar of the contact.
    Uri contactUri = entry.mIsMe ?
            Profile.CONTENT_URI :
            ContentUris.withAppendedId(Contacts.CONTENT_URI, entry.mPersonId);

    InputStream avatarDataStream = Contacts.openContactPhotoInputStream(
                mContext.getContentResolver(),
                contactUri);
    try {
        if (avatarDataStream != null) {
            data = new byte[avatarDataStream.available()];
            avatarDataStream.read(data, 0, data.length);
        }
    } catch (IOException ex) {
        //
    } finally {
        try {
            if (avatarDataStream != null) {
                avatarDataStream.close();
            }
        } catch (IOException e) {
        }
    }

    return data;
}
项目:android-aosp-mms    文件:Contact.java   
private byte[] loadAvatarData(Contact entry) {
    byte [] data = null;

    if ((!entry.mIsMe && entry.mPersonId == 0) || entry.mAvatar != null) {
        return null;
    }

    if (Log.isLoggable(LogTag.CONTACT, Log.DEBUG)) {
        log("loadAvatarData: name=" + entry.mName + ", number=" + entry.mNumber);
    }

    // If the contact is "me", then use my local profile photo. Otherwise, build a
    // uri to get the avatar of the contact.
    Uri contactUri = entry.mIsMe ?
            Profile.CONTENT_URI :
            ContentUris.withAppendedId(Contacts.CONTENT_URI, entry.mPersonId);

    InputStream avatarDataStream = Contacts.openContactPhotoInputStream(
                mContext.getContentResolver(),
                contactUri);
    try {
        if (avatarDataStream != null) {
            data = new byte[avatarDataStream.available()];
            avatarDataStream.read(data, 0, data.length);
        }
    } catch (IOException ex) {
        //
    } finally {
        try {
            if (avatarDataStream != null) {
                avatarDataStream.close();
            }
        } catch (IOException e) {
        }
    }

    return data;
}
项目:CSipSimple    文件:ContactsUtils14.java   
@Override
public CallerInfo findSelfInfo(Context ctxt) {


    CallerInfo callerInfo = new CallerInfo();

    String[] projection = new String[] {
                Profile._ID,
                Profile.DISPLAY_NAME,
                Profile.PHOTO_ID,
                Profile.PHOTO_URI
        };
    Cursor cursor = ctxt.getContentResolver().query(Profile.CONTENT_URI, projection, null, null, null);
    if(cursor != null) {
        try {
            if(cursor.getCount() > 0) {
                cursor.moveToFirst();

                ContentValues cv = new ContentValues();
                DatabaseUtils.cursorRowToContentValues(cursor, cv);
                callerInfo.contactExists = true;
                if(cv.containsKey(Profile.DISPLAY_NAME) ) {
                    callerInfo.name = cv.getAsString(Profile.DISPLAY_NAME);
                }


                if(cv.containsKey(Profile._ID) ) {
                    callerInfo.personId = cv.getAsLong(Profile._ID);
                    callerInfo.contactContentUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, callerInfo.personId);
                }

                if(cv.containsKey(Profile.PHOTO_ID)) {
                    Long photoId = cv.getAsLong(Profile.PHOTO_ID);
                    if(photoId != null) {
                        callerInfo.photoId = photoId;
                    }
                }

                if(cv.containsKey(Profile.PHOTO_URI)) {
                    String photoUri = cv.getAsString(Profile.PHOTO_URI);
                    if(!TextUtils.isEmpty(photoUri)) {
                        callerInfo.photoUri = Uri.parse(photoUri);
                    }
                }

                if(callerInfo.name != null && callerInfo.name.length() == 0) {
                    callerInfo.name = null;
                }

            }
        }catch(Exception e) {
            Log.e(THIS_FILE, "Exception while retrieving cursor infos", e);
        }finally {
            cursor.close();
        }
    }


    return callerInfo;
}
项目:sms_DualCard    文件:MessageListItem.java   
private void updateAvatarView(String addr, boolean isSelf) {
    Drawable avatarDrawable;

    Log.v("MEssageListItem updateAvatarView", "Entered!!");

    if (isSelf || !TextUtils.isEmpty(addr)) {
        Contact contact = isSelf ? Contact.getMe(false) : Contact.get(addr,
                false);
        avatarDrawable = contact.getAvatar(mContext, sDefaultContactImage);

        if (isSelf) {
            mAvatar.assignContactUri(Profile.CONTENT_URI);

            Log.v("MEssageListItem updateAvatarView isSelf", "Entered!!"
                    + Profile.CONTENT_URI);

        } else {
            if (contact.existsInDatabase()) {
                mAvatar.assignContactUri(contact.getUri());

                Log.v("MEssageListItem updateAvatarView contact.existsInDatabase()",
                        "Entered!!" + contact.getUri());

            } else {
                mAvatar.assignContactFromPhone(contact.getNumber(), true);

                Log.v("MEssageListItem updateAvatarView !contact.existsInDatabase()",
                        "Entered!!" + contact.getNumber());

            }
        }
    } else {
        avatarDrawable = sDefaultContactImage;
        Log.v("MEssageListItem updateAvatarView !contact.existsInDatabase()",
                "Entered!! ����else");

    }
    // zaizhe
    // sDefaultContactImage =
    // getResources().getDrawable(R.drawable.ic_contact_picture);
    // avatarDrawable = sDefaultContactImage;
    // zaizhe
    Log.v("MessageListItem", "����������");
    mAvatar.setImageDrawable(avatarDrawable);
}
项目:sms_DualCard    文件:SimMessageListItem.java   
private void updateAvatarView(String addr, boolean isSelf) {
    Drawable avatarDrawable;

    Log.v("SimMessageListItem updateAvatarView", "Entered!!");

    if (isSelf || !TextUtils.isEmpty(addr)) {
        Contact contact = isSelf ? Contact.getMe(false) : Contact.get(addr,
                false);
        avatarDrawable = contact.getAvatar(mContext, sDefaultContactImage);

        if (isSelf) {
            mAvatar.assignContactUri(Profile.CONTENT_URI);

            Log.v("SimMessageListItem updateAvatarView isSelf", "Entered!!"
                    + Profile.CONTENT_URI);

        } else {
            if (contact.existsInDatabase()) {
                mAvatar.assignContactUri(contact.getUri());

                Log.v("SimMessageListItem updateAvatarView contact.existsInDatabase()",
                        "Entered!!" + contact.getUri());

            } else {
                mAvatar.assignContactFromPhone(contact.getNumber(), true);

                Log.v("SimMessageListItem updateAvatarView !contact.existsInDatabase()",
                        "Entered!!" + contact.getNumber());

            }
        }
    } else {
        avatarDrawable = sDefaultContactImage;
        Log.v("SimMessageListItem updateAvatarView !contact.existsInDatabase()",
                "Entered!! ����else");

    }
    // zaizhe
    // sDefaultContactImage =
    // getResources().getDrawable(R.drawable.ic_contact_picture);
    // avatarDrawable = sDefaultContactImage;
    // zaizhe
    Log.v("SimMessageListItem", "����������");
    mAvatar.setImageDrawable(avatarDrawable);
}
项目:dashclock-owninfo    文件:OwninfoWidget.java   
@Override
protected void onUpdateData(int intReason) {

    Log.d(getTag(), "Fetching phone owner information");
    ExtensionData edtInformation = new ExtensionData();
    setUpdateWhenScreenOn(false);

    try {

        Log.d(getTag(), "Get the phone owner from the Me contact");
        Uri uriProfile = Uri.withAppendedPath(Profile.CONTENT_URI, Contacts.Data.CONTENT_DIRECTORY);
        Cursor curOwner = getContentResolver().query(uriProfile,
                new String[]{Email.ADDRESS, Email.IS_PRIMARY, Profile.DISPLAY_NAME,},
                ContactsContract.Contacts.Data.MIMETYPE + " = ?",
                new String[]{Email.CONTENT_ITEM_TYPE},
                ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");

        if (!getString("heading", "").isEmpty()) {
            edtInformation.expandedTitle(getString("heading", ""));
        }

        if (!getString("message", "").isEmpty()) {
            edtInformation.expandedBody(getString("message", ""));
        }

        while (curOwner.moveToNext()) {

            Integer intName = curOwner.getColumnIndex(ContactsContract.Profile.DISPLAY_NAME);
            if (!curOwner.getString(intName).isEmpty() && edtInformation.expandedTitle() == null) {
                edtInformation.expandedTitle(curOwner.getString(intName));
            }

            Integer intAddress = curOwner.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS);
            if (!curOwner.getString(intAddress).isEmpty() && edtInformation.expandedBody() == null) {
                edtInformation.expandedBody(curOwner.getString(intAddress));
            }

        }

        edtInformation.clickIntent(new Intent(Intent.ACTION_VIEW).setData(Profile.CONTENT_URI));
        edtInformation.visible(true);
        curOwner.close();

    } catch (Exception e) {
        edtInformation.visible(false);
        Log.e(getTag(), "Encountered an error", e);
        ACRA.getErrorReporter().handleSilentException(e);
    }

    edtInformation.icon(R.drawable.ic_dashclock);
    doUpdate(edtInformation);

}