我尝试更改联系人铃声但我收到此错误
android.database.sqlite.SQLiteException:没有这样的列:custom_ringtone(代码1):,同时编译:UPDATE数据SET data11 =?,custom_ringtone =?,data10 = ?, data1 =?,data2 =? WHERE _id =?
这是我的代码:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
Builder builder = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI);
builder.withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND " + ContactsContract.Data.MIMETYPE + "=?", new String[]{String.valueOf(ContactID), ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE});
builder.withValue(ContactsContract.Data.CUSTOM_RINGTONE, myringtone.getAbsolutePath());
builder.withValue(ContactsContract.CommonDataKinds.Phone.CUSTOM_RINGTONE, myringtone.getAbsolutePath()); //that was my alternative solution because I didn't know which property to change
ops.add(builder.build());
ContentProviderResult[] res;
try
{
res = getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
}
catch (Exception e)
{
e.printStackTrace();
}
我错过了什么吗?
答案 0 :(得分:0)
我找到了一个使用ContentValues而不是ContentProviderOperations的解决方案:
Cursor c;
c = getContentResolver().query(
CommonDataKinds.Phone.CONTENT_URI,
null,
CommonDataKinds.Phone.CONTACT_ID +" = ?",
new String[]{ContactID}, null);
try
{
c.moveToFirst();
Uri localUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, ContactID);
ContentValues localContentValues = new ContentValues();
localContentValues.put(ContactsContract.Contacts.CUSTOM_RINGTONE, ringtonefileabsolutepath);
getContentResolver().update(localUri, localContentValues, null, null);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
c.close();
}