Android 编辑联系人

发布于 2024-09-08 12:53:28 字数 1499 浏览 7 评论 0原文

您好,我正在尝试向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一人独醉 2024-09-15 12:53:28

插入 Data.CONTENT_URI 而不是 Phone.CONTENT_URI,同时插入带有 Phone.CONTENT_ITEM_TYPEData.MIMETYPE 列。

Insert into Data.CONTENT_URI instead of Phone.CONTENT_URI also insert the Data.MIMETYPE column with Phone.CONTENT_ITEM_TYPE.

一百个冬季 2024-09-15 12:53:28

您是否在 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

梦回旧景 2024-09-15 12:53:28

您可能还想检查已安装的应用程序与程序内存。我的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文