我知道如何使用How to add new contacts in android以编程方式为本机应用创建名称,手机号码和电子邮件ID的联系人。但我不知道如何与铃声建立联系。请帮我。提前致谢
我在将联系人添加到本机应用程序后获得了添加铃声的解决方案:
String select = "(" + ContactsContract.Contacts.DISPLAY_NAME + " == \"" +first_name+ "\" )";
Cursor c1 = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
CONTACTS_SUMMARY_PROJECTION, select, null, ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
startManagingCursor(c1);
int id=0;
if (c1.moveToNext()) {
id = new Integer(c1.getString(0)).intValue();
Toast.makeText(getApplicationContext(), "CONTACT ID: "+id+"", Toast.LENGTH_LONG).show();
}
ContentResolver cr = getContentResolver();
cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
ContentValues values=new ContentValues(); values.put(ContactsContract.Contacts.CUSTOM_RINGTONE, newgroup_ringtone);
cr.update(ContactsContract.Contacts.CONTENT_URI, values, Contacts._ID + "=" + id, null);
答案 0 :(得分:1)
为什么不先添加联系人然后检索该联系人并使用以下代码更新联系人:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Contacts.CONTENT_URI)
.withSelection(ContactsContract.Contacts._ID + " = ?", new String[] {id})
.withValue(ContactsContract.Contacts.STARRED, starred)
.withValue(ContactsContract.Contacts.SEND_TO_VOICEMAIL, sendToVoicemail)
.withValue(ContactsContract.Contacts.CUSTOM_RINGTONE, ringtone)
.build());
try {
resolver.applyBatch(ContactsContract.AUTHORITY, ops);
}