Android 编辑联系人
您好,我正在尝试向 Android 2.1 上的现有联系人添加电话号码。我目前正在使用:
ContentValues values = new ContentValues();
values.put(Phone.RAW_CONTACT_ID,cursor.getColumnIndex(Phone.CONTACT_ID));
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI,null, selection, null,ContactsContract.Contacts.DISPLAY_NAME+" COLLATE LOCALIZED ASC");
if (cursor.getCount() > 0) {
cursor.moveToPosition(oldcontactid);
contactid = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
values.put(Phone.RAW_CONTACT_ID,cursor.getColumnIndex(Phone.CONTACT_ID));
if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{contactid}, null);
while (pCur.moveToNext()) {
values.put(Phone.NUMBER,pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
values.put(Phone.TYPE, Phone.TYPE_MOBILE);
}
pCur.close();
}
}
Uri uri = getContentResolver().insert(Phone.CONTENT_URI, values);
但我收到一个错误:
java.lang.UnsupportedOperationException: Unknown uri: content://com.android.contacts/data/phones
我该如何解决这个问题?
感谢您的帮助, NG93
hi im trying to add a phone number to an existing contact on android 2.1. Im currently using:
ContentValues values = new ContentValues();
values.put(Phone.RAW_CONTACT_ID,cursor.getColumnIndex(Phone.CONTACT_ID));
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI,null, selection, null,ContactsContract.Contacts.DISPLAY_NAME+" COLLATE LOCALIZED ASC");
if (cursor.getCount() > 0) {
cursor.moveToPosition(oldcontactid);
contactid = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
values.put(Phone.RAW_CONTACT_ID,cursor.getColumnIndex(Phone.CONTACT_ID));
if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{contactid}, null);
while (pCur.moveToNext()) {
values.put(Phone.NUMBER,pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
values.put(Phone.TYPE, Phone.TYPE_MOBILE);
}
pCur.close();
}
}
Uri uri = getContentResolver().insert(Phone.CONTENT_URI, values);
but i get an error:
java.lang.UnsupportedOperationException: Unknown uri: content://com.android.contacts/data/phones
how would i be able to fix this?
thanks for any help,
ng93
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
检查这两个链接,它将有所帮助:)
check this both link it will help :)
插入
Data.CONTENT_URI
而不是Phone.CONTENT_URI
,同时插入带有Phone.CONTENT_ITEM_TYPE
的Data.MIMETYPE
列。Insert into
Data.CONTENT_URI
instead ofPhone.CONTENT_URI
also insert theData.MIMETYPE
column withPhone.CONTENT_ITEM_TYPE
.您是否在 AndroidManifest.xml 中设置了正确的权限?据我所知,默认情况下对个人信息(联系人)的访问是受到限制的。
有关 android 中权限系统的更多信息,请参阅此处
Have you set the correct permissions in the AndroidManifest.xml? As far as I know the access to the personal information (contacts) is restricted by default.
see here for more about the permission system in android
您可能还想检查已安装的应用程序与程序内存。我的 Droid Eris 在联系人和几乎任何联系人感知应用程序中都运行良好。
直到我超过了某个内存负载点。 VZW 第一级支持对我没有好处,我不得不坚持第二级支持。终于得到了认识他菠菜的人的答复。他告诉我,我手机上的应用程序太多了,这是一个已知问题。
仍然没有削减我的工作集足以让联系人编辑工作:-(
/s/ BezantSoft
You also might want to check your installed apps vs program memory. My Droid Eris worked fine on contacts and from just about any contacts aware application, too.
Until I went past some point of memory load. VZW support 1st level did me no good, I had to insist on 2nd level support. Finally got an answer from someone who knew his spinach. He told be that I had too many apps on the phone, and that this was a known problem.
Still have not cut my working set down enough to get contact edit working :-(
/s/ BezantSoft