I'm building an app where when a image is clicked the user sees the contacts list and picks one. After clicking on it, it's contact picture should change to the image clicked in the first place. Here's how i implement it:
....
Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
startActivityForResult(intent, SELECT_CONTACT);
.....
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_CONTACT) {
Uri contactData = data.getData();
????? what should come here???
}
}
}
My question is how do i acces and change the contact picture? Thank you
First, get the Uri for the Contacts first raw contact:
Then, convert a bitmap to a byte array:
Finally, set the byte array as the raw contact's photo:
EDIT
Be sure to include these two permissions in your manifest: