android.provider.ContactsContract.Profile Java Examples

The following examples show how to use android.provider.ContactsContract.Profile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PhoneHelper.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
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 (Throwable 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);
}
 
Example #2
Source File: PhoneHelper.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
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 (Throwable 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);
}
 
Example #3
Source File: MessagingBuilder.java    From decorator-wechat with Apache License 2.0 4 votes vote down vote up
private static Person buildPersonFromProfile(final Context context) {
	return new Person.Builder().setName(context.getString(R.string.self_display_name))
			.setIcon(IconCompat.createWithContentUri(Uri.withAppendedPath(Profile.CONTENT_URI, Contacts.Photo.DISPLAY_PHOTO))).build();
}
 
Example #4
Source File: ContactsUtils14.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
@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;
}