我想问一下
android 2.1之后 如何新增,更新,删除 sim卡中联系人。这个问题在网上搜索了很久,也没有找到具体的解决方法。
请大家帮忙,看看谁知道如何处理?
权限应该是没有问题的,
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />uri也应该是正确的,使用
Uri uri = Uri.parse("content://icc/adn");
String[] projection = new String[] { "id","name", "number" };
mCursor = managedQuery(uri, projection, null, null,
null);
可以查询出sim卡中的已有联系人,但是就是不知道该如何实现 新增,更新,删除等功能。
android 2.1之后 如何新增,更新,删除 sim卡中联系人。这个问题在网上搜索了很久,也没有找到具体的解决方法。
请大家帮忙,看看谁知道如何处理?
权限应该是没有问题的,
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />uri也应该是正确的,使用
Uri uri = Uri.parse("content://icc/adn");
String[] projection = new String[] { "id","name", "number" };
mCursor = managedQuery(uri, projection, null, null,
null);
可以查询出sim卡中的已有联系人,但是就是不知道该如何实现 新增,更新,删除等功能。
Uri uri = Uri.parse("content://icc/adn");
ContentValues values= new ContentValues();
values.put("tag", "lktest");
values.put("number", "222");
Uri cccd = getContentResolver().insert(uri ,values);
使用上面的代码,是可以插入的,但是只能在每次重新开机之后,新增一条记录,之后就不起作用了。
我是在 三星 i5700上面测试的。大家可以看看各自的手机是否也是这个现象。有没有人实现过这个功能?或者可以提供相应的参考文档?既然可以插入一次,那么我觉得就是该方法在使用上面有某些限制,但是实在是不知道是什么限制,盼望高手指教:)
包括增加,删除,修改
支持sim卡,USIM卡
支持中文等等。。
public Uri insert(Uri url, ContentValues initialValues) {
Uri resultUri;
int efType;
String pin2 = null; if (DBG) log("insert"); int match = URL_MATCHER.match(url);
switch (match) {
case ADN:
efType = IccConstants.EF_ADN;
break; case FDN:
efType = IccConstants.EF_FDN;
pin2 = initialValues.getAsString("pin2");
break; default:
throw new UnsupportedOperationException(
"Cannot insert into URL: " + url);
} String tag = initialValues.getAsString("tag");
String number = initialValues.getAsString("number");
// TODO(): Read email instead of sending null.
boolean success = addIccRecordToEf(efType, tag, number, null, pin2); if (!success) {
return null;
} StringBuilder buf = new StringBuilder("content://icc/");
switch (match) {
case ADN:
buf.append("adn/");
break; case FDN:
buf.append("fdn/");
break;
} // TODO: we need to find out the rowId for the newly added record
buf.append(0); resultUri = Uri.parse(buf.toString()); /*
// notify interested parties that an insertion happened
getContext().getContentResolver().notifyInsert(
resultUri, rowID, null);
*/ return resultUri;
}
ContentValues values = new ContentValues();
values.clear();
values.put("tag", oldName);
values.put("number", oldPhoneNumber);
values.put("newTag", newName);
values.put("newNumber", newPhoneNumber);
long res = 0;
Uri uri = Uri.parse("content://icc/adn");
res = this.cr.update(uri, values, null, null);
System.out.println("修改结果 ====== "+res);
return res;过了那么长时间了,不知你的问题解决了没有,希望能帮到你