我的代码有问题.我需要获取联系人照片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)