小编art*_*boy的帖子

在Android 2.3和Android 4.0上联系照片uri

我的代码有问题.我需要获取联系人照片uri,并在我的ImageView中显示图片.我编写了这段代码,它在Android 2.3中正常运行.

Uri myUri = getPhotoUriById( this, contactId );
(ImageView)myImageView.setImageUri( myUri );

public static Uri getPhotoUriById( Context context, Long id ) {
    if( id == null || context == null ) return null;

    Uri photo = Uri.parse( "android.resource://"+ context.getPackageName() +"/" + R.drawable.no_photo );

    Cursor cursor = context.getContentResolver().query( Contacts.CONTENT_URI,
            new String[]{ Contacts.PHOTO_ID },
            Contacts._ID + " = " + id + " AND " + Contacts.PHOTO_ID + " != 0",
            null,
            null );
    if( cursor != null ) {
        if( cursor.moveToFirst()) …
Run Code Online (Sandbox Code Playgroud)

android uri android-contacts

4
推荐指数
1
解决办法
4760
查看次数

标签 统计

android ×1

android-contacts ×1

uri ×1