android - Nexus 4 dialer - Creating contact without phone number -
i trying create contact programatically without phone number. manage create when open dialer crashes. if open contacts ok.
also, if add contact manually without phone number works ok.
i working nexus 4 - kitkat 4.4.2.
this code use:
/** * add new contact contacts list , contacts db. * @param contact * @param contactkey * @param ctx */ public void addcontact(retrievable contact,string name,string contactkey ,final activity ctx){ initializedb(ctx); if(groupid== null) groupid = getgroupid(ctx); arraylist<contentprovideroperation> ops = new arraylist<contentprovideroperation>(); ops.add(contentprovideroperation.newinsert(contactscontract.rawcontacts.content_uri) .withvalue(contactscontract.rawcontacts.account_type, null) .withvalue(contactscontract.rawcontacts.account_name, null) .build()); ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri) .withvaluebackreference(contactscontract.data.raw_contact_id, 0) .withvalue(contactscontract.data.mimetype,contactscontract.commondatakinds.structuredname.content_item_type) .withvalue(contactscontract.commondatakinds.structuredname.display_name, name) .build()); //need check because if null crash dialer in sdk 4.4.2 if(contact.phone != null && contact.phone !=" "){ ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri) .withvaluebackreference(contactscontract.data.raw_contact_id, 0) .withvalue(contactscontract.data.mimetype,contactscontract.commondatakinds.phone.content_item_type) .withvalue(contactscontract.commondatakinds.phone.number, contact.phone) .withvalue(contactscontract.commondatakinds.phone.type,phone.type_work) .build()); } else{ ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri) .withvaluebackreference(contactscontract.data.raw_contact_id, 0) .withvalue(contactscontract.data.mimetype,contactscontract.commondatakinds.phone.content_item_type) .withvalue(contactscontract.commondatakinds.phone.number, new string()) .build()); } if(contact.phone2 != null && contact.phone2 !=" "){ ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri) .withvaluebackreference(contactscontract.data.raw_contact_id, 0) .withvalue(contactscontract.data.mimetype,contactscontract.commondatakinds.phone.content_item_type) .withvalue(contactscontract.commondatakinds.phone.number, contact.phone2) .withvalue(contactscontract.commondatakinds.phone.type,phone.type_work) .build()); } if(contact.phone3 != null && contact.phone3 !=" "){ ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri) .withvaluebackreference(contactscontract.data.raw_contact_id, 0) .withvalue(contactscontract.data.mimetype,contactscontract.commondatakinds.phone.content_item_type) .withvalue(contactscontract.commondatakinds.phone.number, contact.phone3) .withvalue(contactscontract.commondatakinds.phone.type,phone.type_work) .build()); } ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri) .withvaluebackreference(contactscontract.data.raw_contact_id, 0) .withvalue(contactscontract.data.mimetype,contactscontract.commondatakinds.phone.content_item_type) .withvalue(contactscontract.commondatakinds.phone.number, contact.fax) .withvalue(contactscontract.commondatakinds.phone.type,phone.type_fax_work) .build()); ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri) .withvaluebackreference(contactscontract.data.raw_contact_id, 0) .withvalue(contactscontract.data.mimetype, contactscontract.commondatakinds.structuredpostal.content_item_type) .withvalue(contactscontract.commondatakinds.structuredpostal.street,(" ".equals(contact.getaddress())?contact.location:contact.getaddress())) .build()); ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri) .withvaluebackreference(contactscontract.data.raw_contact_id, 0) .withvalue(contactscontract.data.mimetype,contactscontract.commondatakinds.organization.content_item_type) .withvalue(contactscontract.commondatakinds.organization.company,ctx.getresources().getstring(r.string.meuhedet)) .build()); ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri) .withvaluebackreference(contactscontract.data.raw_contact_id, 0) .withvalue(contactscontract.data.mimetype,contactscontract.commondatakinds.groupmembership.content_item_type) .withvalue(contactscontract.commondatakinds.groupmembership.group_row_id, long.parselong(groupid)) .build()); bytearrayoutputstream baos = new bytearrayoutputstream(); bitmap photo = bitmapfactory.decoderesource(ctx.getresources(),r.drawable.logo_meuhedet); photo.compress(bitmap.compressformat.png, 100, baos); 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.photo, baos.tobytearray()) .build()); try { contentproviderresult [] res =ctx.getcontentresolver().applybatch(contactscontract.authority, ops); rawcontactid = contenturis.parseid(res[0].uri); boolean result = db.savecontactsintodatabase(rawcontactid, contact.index, contactkey); if(result){ ((activity) ctx).runonuithread(new runnable() { @override public void run() { toast.maketext(ctx, r.string.successfully_saved_contact, toast.length_short).show(); } }); } } catch (exception e) { } }
i following when open dialer:
fatal exception: asynctask #4 process: com.google.android.dialer, pid: 8233 java.lang.runtimeexception: error occured while executing doinbackground() @ android.os.asynctask$3.done(asynctask.java:300) @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355) @ java.util.concurrent.futuretask.setexception(futuretask.java:222) @ java.util.concurrent.futuretask.run(futuretask.java:242) @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:841) caused by: java.lang.illegalargumentexception: bind value @ index 2 null @ android.database.sqlite.sqliteprogram.bindstring(sqliteprogram.java:164) @ com.android.dialer.database.dialerdatabasehelper.insertupdatedcontactsandnumberprefix(dialerdatabasehelper.java:632) @ com.android.dialer.database.dialerdatabasehelper.updatesmartdialdatabase(dialerdatabasehelper.java:784) @ com.android.dialer.database.dialerdatabasehelper$smartdialupdateasynctask.doinbackground(dialerdatabasehelper.java:481) @ java.util.concurrent.futuretask.run(futuretask.java:237) ... 4 more
i have tried not putting number @ all, putting null , putting empty string , still same.
we tried using different dialler , works ok.
is problem dialler or missing field should setting?
the right way not add number. adding null or empty string lead same crash.
also, since doing new insert not update existing contact. need newupdate that.
Comments
Post a Comment