Some issues when adding image to android contact -


i working on android application. in app have add details , image android contact. used following code

private void addcontact() {             // todo auto-generated method stub              arraylist<contentprovideroperation> ops = new arraylist<contentprovideroperation>();             int rawcontactinsertindex = ops.size();             ops.add(contentprovideroperation.newinsert(rawcontacts.content_uri)                .withvalue(rawcontacts.account_type, null)                .withvalue(rawcontacts.account_name,null )                .build());             ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri)                .withvaluebackreference(contactscontract.data.raw_contact_id, rawcontactinsertindex)                .withvalue(data.mimetype,phone.content_item_type)                .withvalue(phone.number, "9x-xxxxxxxxx")                .build());              bitmap bm = getbitmapfromurl(imageurl);              bytearrayoutputstream stream = new bytearrayoutputstream();             bm.compress(bitmap.compressformat.png , 75, stream);              ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri)                        .withvalue(contactscontract.data.raw_contact_id, 9) // here 9 _id i'm inserting image                        .withvalue(contactscontract.data.is_super_primary, 1)                        .withvalue(contactscontract.data.mimetype,contactscontract.commondatakinds.photo.content_item_type)                        .withvalue(contactscontract.commondatakinds.photo.photo,stream.tobytearray())                        .build());                ops.add(contentprovideroperation.newinsert(android.provider.contactscontract.data.content_uri)                .withvaluebackreference(data.raw_contact_id, rawcontactinsertindex)                .withvalue(data.mimetype,structuredname.content_item_type)                .withvalue(structuredname.display_name, "sarath")                .build());                try {                 contentproviderresult[] res = getcontentresolver().applybatch(contactscontract.authority, ops);             } catch (remoteexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (operationapplicationexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }            }     }); 

the code working without exception. contact added contact contact image not loading. second doubt have 3 type phoen numbers (home, work, mobile) .i add 1 phone number how can add 3 . how add address , email id.. please me friends

at last got answer issue posting here. may helpful somebody.

private void addcontact(string name, string phone, string profilepic) {     // todo auto-generated method stub        arraylist<contentprovideroperation> ops = new arraylist<contentprovideroperation>();     int rawcontactinsertindex = ops.size();      ops.add(contentprovideroperation.newinsert(rawcontacts.content_uri)             .withvalue(rawcontacts.account_type, null)             .withvalue(rawcontacts.account_name, null).build());     ops.add(contentprovideroperation             .newinsert(contactscontract.data.content_uri)             .withvaluebackreference(contactscontract.data.raw_contact_id,                     rawcontactinsertindex)             .withvalue(data.mimetype, phone.content_item_type)             .withvalue(phone.number, phone).build());      drawable dr = getresources().getdrawable(r.drawable.ic_launcher);      bitmap bm = getbitmapfromurl(profilepic);      // bm = bitmapfactory.decoderesource(getresources(),     // r.drawable.ic_launcher);     //      bytearrayoutputstream baos = new bytearrayoutputstream();     bm.compress(bitmap.compressformat.jpeg, 80, baos);     byte[] b = baos.tobytearray();      ops.add(contentprovideroperation             .newinsert(contactscontract.data.content_uri)             .withvaluebackreference(contactscontract.data.raw_contact_id, 0)             .withvalue(                     contactscontract.data.mimetype,                     contactscontract.commondatakinds.photo.content_item_type)             .withvalue(contactscontract.commondatakinds.photo.data15, b)             .build());      // bytearrayoutputstream stream = new bytearrayoutputstream();     // bm.compress(bitmap.compressformat.png , 75, stream);     //     // ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri)     // .withvalue(contactscontract.data.raw_contact_id, 9) // here 9 _id     // i'm inserting image     // .withvalue(contactscontract.data.is_super_primary, 1)     // .withvalue(contactscontract.data.mimetype,contactscontract.commondatakinds.photo.content_item_type)     // .withvalue(contactscontract.commondatakinds.photo.photo,stream.tobytearray())     // .build());      ops.add(contentprovideroperation             .newinsert(android.provider.contactscontract.data.content_uri)             .withvaluebackreference(data.raw_contact_id,                     rawcontactinsertindex)             .withvalue(data.mimetype, structuredname.content_item_type)             .withvalue(structuredname.display_name, name).build());      try {         contentproviderresult[] res = getcontentresolver().applybatch(                 contactscontract.authority, ops);          toast.maketext(getapplicationcontext(),                 "contact added phone", toast.length_long).show();     } catch (remoteexception e) {         // todo auto-generated catch block         e.printstacktrace();     } catch (operationapplicationexception e) {         // todo auto-generated catch block         e.printstacktrace();     }  } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -