在 HTC 上插入联系人
我在 HTC 设备中插入联系人时遇到问题, 看起来它在其他设备上运行良好。 我使用的代码来自:在 Android 2.2 中插入联系人
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());
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
.withValue(Data.MIMETYPE,
StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, "Mike Sullivan")
.build());
ContentProviderResult[] res = getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
,我得到:
07-18 09:37:49.832: ERROR/DatabaseUtils(209): Writing exception to parcel
07-18 09:37:49.832: ERROR/DatabaseUtils(209): java.lang.NullPointerException
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.HtcContactsProvider2$PhoneDataRowHandler.insert(HtcContactsPr ovider2.java:4614)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.ContactsProvider2.insertData(ContactsProvider2.java:3599)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.ContactsProvider2.insertInTransaction(ContactsProvider2.java:3394)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.CContactsProvider2.insertInTransaction(CContactsProvider2.java:191)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.HtcContactsProvider2.insertInTransaction(HtcContactsProvider2.java:1677)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.SQLiteContentProvider.insert(SQLiteContentProvider.java:106)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.ContactsProvider2.insert(ContactsProvider2.java:3159)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.CContactsProvider2.insert(CContactsProvider2.java:117)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at android.content.ContentProviderOperation.apply(ContentProviderOperation.java:214)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.SQLiteContentProvider.applyBatch(SQLiteContentProvider.java:216)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.ContactsProvider2.applyBatch(ContactsProvider2.java:3193)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.CContactsProvider2.applyBatch(CContactsProvider2.java:145)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at android.content.ContentProvider$Transport.applyBatch(ContentProvider.java:199)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:202)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at android.os.Binder.execTransact(Binder.java:288)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at dalvik.system.NativeStart.run(Native Method)
I have problems with inserting contacts in HTC devices,
it looks that it works fine on other devices.
I'm using code from: Inserting contacts in Android 2.2
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());
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
.withValue(Data.MIMETYPE,
StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, "Mike Sullivan")
.build());
ContentProviderResult[] res = getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
and I'm getting:
07-18 09:37:49.832: ERROR/DatabaseUtils(209): Writing exception to parcel
07-18 09:37:49.832: ERROR/DatabaseUtils(209): java.lang.NullPointerException
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.HtcContactsProvider2$PhoneDataRowHandler.insert(HtcContactsPr ovider2.java:4614)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.ContactsProvider2.insertData(ContactsProvider2.java:3599)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.ContactsProvider2.insertInTransaction(ContactsProvider2.java:3394)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.CContactsProvider2.insertInTransaction(CContactsProvider2.java:191)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.HtcContactsProvider2.insertInTransaction(HtcContactsProvider2.java:1677)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.SQLiteContentProvider.insert(SQLiteContentProvider.java:106)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.ContactsProvider2.insert(ContactsProvider2.java:3159)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.CContactsProvider2.insert(CContactsProvider2.java:117)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at android.content.ContentProviderOperation.apply(ContentProviderOperation.java:214)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.SQLiteContentProvider.applyBatch(SQLiteContentProvider.java:216)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.ContactsProvider2.applyBatch(ContactsProvider2.java:3193)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at com.android.providers.contacts.CContactsProvider2.applyBatch(CContactsProvider2.java:145)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at android.content.ContentProvider$Transport.applyBatch(ContentProvider.java:199)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:202)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at android.os.Binder.execTransact(Binder.java:288)
07-18 09:37:49.832: ERROR/DatabaseUtils(209): at dalvik.system.NativeStart.run(Native Method)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个答案:
https://stackoverflow.com/a/4387890/244521
建议将 Phone.TYPE 添加到您的 ContactsContract.Data.CONTENT_URI 插入中。 Android 文档有一个很好的示例:
http://developer.android.com/reference/android/provider/ ContactsContract.Data.html
您发布的代码没有 Phone.TYPE 行。
This answer:
https://stackoverflow.com/a/4387890/244521
Suggests adding Phone.TYPE to your ContactsContract.Data.CONTENT_URI insert. The Android documentation has a good example:
http://developer.android.com/reference/android/provider/ContactsContract.Data.html
The code you posted has no line for Phone.TYPE.