在Android中将图像设置为联系人照片

时间:2013-01-24 09:25:58

标签: android android-contacts

我有图片URI。现在我想在Android中设置为照片如何开始? 这是我的功能

        Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{id}, null);
            if(cursor.moveToNext())
            {

                    mContactName = cursor.getString(cursor.getColumnIndex((ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)));
                    mPhotoUri = Uri.withAppendedPath(result, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
                    mContactNumber = cursor.getString(cursor.getColumnIndex((ContactsContract.CommonDataKinds.Phone.NUMBER)));

                    Log.i("Dante", "ContactName = "+ mContactName  );
                    Log.i("Dante", "mContactNumber  ="+mContactNumber);
                    Log.i("Dante", " PhotoURI "+mPhotoUri );

            }


            ContentResolver cr = mContext.getContentResolver();
            int i = collagelistadaper.getItemPositon();
            ContentValues values = new ContentValues();   
            values.put(ContactsContract.Contacts.Photo.CONTENT_DIRECTORY,                                       Uri.fromFile(quiltFolder.listFiles()[i]).toString()); //ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValue(ContactsContract.Contacts.Photo.CONTENT_DIRECTORY, values);     
            Uri result1 = cr.insert(ContactsContract.Data.CONTENT_URI ,values);     
            // getContentResolver().update(mPhotoUri,values,null,null);             
        mPhotoUri = Uri.withAppendedPath(result,ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);

1 个答案:

答案 0 :(得分:4)

试试这个,

Uri sendUri = Uri.fromFile(externalFile)
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
            intent.setDataAndType(sendUri, "image/jpg");
            intent.putExtra("mimeType", "image/jpg");
            startActivityForResult(Intent.createChooser(intent, "Set As"), 200);