如何删除SIM卡联系人的机器人 [英] How to delete sim card contact in android
本文介绍了如何删除SIM卡联系人的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的code从手机中删除联系人
below is my code for delete contact from phone
Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(phone));
Cursor cur = mContext.getContentResolver().query(contactUri, null,
null, null, null);
boolean flag = false;
try {
if (cur.moveToFirst()) {
do {
if (cur.getString(
cur.getColumnIndex(PhoneLookup.DISPLAY_NAME))
.equalsIgnoreCase(name)) {
String lookupKey = cur
.getString(cur
.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(
ContactsContract.Contacts.CONTENT_LOOKUP_URI,
lookupKey);
mContext.getContentResolver().delete(uri, null, null);
flag=true;
break;
}
} while (cur.moveToNext());
}
} catch (Exception e) {
flag=false;
System.out.println(e.getStackTrace());
}
删除手机联系人工作正常,但SIM卡联系人删除临时的意思是当我的手机是重新启动我的联系方式是恢复我删除。 在这个问题找到解决方案帮助。 谢谢...
delete contact from phone is working fine but sim contact delete temporary mean when my phone is restart my contact is recover that i deleted. help in find solution for this problem. Thanks...
推荐答案
您要使用的URI是这个:内容:// ICC / ADN /
The URI you want to use is this one : content://icc/adn/
此外,你必须使用名称
和号
来删除联系人。
Moreover, you have to use the name
and the number
to delete a contact.
尝试像这样(为我的作品):
Try something like this (works for me) :
Uri simUri = Uri.parse("content://icc/adn/");
ContentResolver mContentResolver = this.getContentResolver();
Cursor c = mContentResolver.query(simUri, null, null, null, null);
if (c.moveToFirst())
{
do
{
if (/* your condition here */)
{
mContentResolver.delete(
simUri,
"tag='" + c.getString(c.getColumnIndex("name")) +
"' AND " +
"number='" + c.getString(c.getColumnIndex("number")) + "'"
, null);
break;
}
}
while (c.moveToNext());
}
当然,不要忘了这些权限:
Off course, don't forget these permissions :
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
这篇关于如何删除SIM卡联系人的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文