0

I'm trying to add an entry in the Contacts. If to choose the option "USIM only", app "Contacts" is closed and there is a window with the error: "Unfortunately, Contacts has stopped". If to choose any other option it works well

Sample code:

val intent = Intent (ContactsContract.Intents.Insert.ACTION)
intent.type = ContactsContract.RawContacts.CONTENT_TYPE
intent.putExtra (ContactsContract.Intents.Insert.NAME, contact.name + "" + contact.secondName)
intent.putExtra (ContactsContract.Intents.Insert.PHONE, contact.phoneNumber)
intent.putExtra (ContactsContract.Intents.Insert.EMAIL, contact.email)
startActivity (intent)

Exception in LogCat:

E/AndroidRuntime: FATAL EXCEPTION: main
                                               java.lang.RuntimeException: Failure delivering result ResultInfo{who=android:fragment:0, request=1, result=-1, data=Intent { (has extras) }} to activity {com.android.contacts/com.android.contacts.activities.ContactEditorActivity}: java.lang.NullPointerException
                                                   at android.app.ActivityThread.deliverResults(ActivityThread.java:3302)
                                                   at android.app.ActivityThread.handleSendResult(ActivityThread.java:3345)
                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:149)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1348)
                                                   at android.os.Handler.dispatchMessage(Handler.java:99)
                                                   at android.os.Looper.loop(Looper.java:153)
                                                   at android.app.ActivityThread.main(ActivityThread.java:5086)
                                                   at java.lang.reflect.Method.invokeNative(Native Method)
                                                   at java.lang.reflect.Method.invoke(Method.java:511)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
                                                   at dalvik.system.NativeStart.main(Native Method)
                                                Caused by: java.lang.NullPointerException
                                                   at com.android.contacts.model.EntityModifier.canInsert(EntityModifier.java:94)
                                                   at com.android.contacts.model.EntityModifier.parseExtras(EntityModifier.java:625)
                                                   at com.android.contacts.editor.ContactEditorFragment.bindEditorsForNewContact(ContactEditorFragment.java:839)
                                                   at com.android.contacts.editor.ContactEditorFragment.bindEditorsForNewContact(ContactEditorFragment.java:798)
                                                   at com.android.contacts.editor.ContactEditorFragment.createContact(ContactEditorFragment.java:765)
                                                   at com.android.contacts.editor.ContactEditorFragment.onActivityResult(ContactEditorFragment.java:2134)
                                                   at android.app.Activity.dispatchActivityResult(Activity.java:5208)
                                                   at android.app.ActivityThread.deliverResults(ActivityThread.java:3298)
                                                   at android.app.ActivityThread.handleSendResult(ActivityThread.java:3345) 
                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:149) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1348) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                   at android.os.Looper.loop(Looper.java:153) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:5086) 
                                                   at java.lang.reflect.Method.invokeNative(Native Method) 
                                                   at java.lang.reflect.Method.invoke(Method.java:511) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584) 
                                                   at dalvik.system.NativeStart.main(Native Method) 

Options to add to contacts

Error

Dim
  • 101
  • 1
  • There is a NullPointerException in your error message!! – Eenvincible Aug 15 '16 at 13:14
  • @Eenvincible +1. Add your source code also so that we can look for the problems. What is EntityModifier? What is ContactEditorFragment? What's happening inside them ? – Recomer Aug 15 '16 at 13:17
  • EntityModifier https://android.googlesource.com/platform/packages/apps/Contacts/+/froyo/src/com/android/contacts/model/EntityModifier.java – Dim Aug 15 '16 at 13:34
  • Is it possible remove the option "USIM-only"? – Dim Aug 15 '16 at 13:37
  • Refer this link http://stackoverflow.com/questions/4075694/inserting-contacts-in-android-2-2 – Hardik Parmar Aug 15 '16 at 13:44
  • @HardikParmar thanks. But I'm looking for a solution to add an entry in the contacts using an Intent – Dim Aug 15 '16 at 13:50

0 Answers0