android电话本中收藏夹的一些操作

/**
 * 添加到收藏夹
 * @param _id
 */
@SuppressWarnings("deprecation")
private void addKeepedContacts(long _id){
ContentResolver contentResolver = ContactActivity.this.getContentResolver();
Cursor cusor = null;
@SuppressWarnings("deprecation")
String[] projection = new String[] { Contacts.People._ID, Contacts.People.NAME, Contacts.People.NUMBER };
cusor = contentResolver.query(Contacts.People.CONTENT_URI, projection, Contacts.People._ID + "=?", new String[] { _id + "" }, Contacts.People.NAME + " ASC");
    cusor.moveToFirst();
ContentValues values = new ContentValues();
Uri uri = Uri.withAppendedPath(Contacts.People.CONTENT_URI, cusor.getString(cusor.getColumnIndex(Contacts.People._ID)));
// values.put(Contacts.People.NAME, newName);
values.put(Contacts.People.STARRED, 1);
// values.put(Contacts.Phones.NUMBER, newPhoneNum);
contentResolver.update(uri, values, null, null);
Toast.makeText(ContactActivity.this, ContactActivity.this.getResources().getString(R.string.add_succeed), Toast.LENGTH_SHORT).show();
}
/**
 * 从收藏夹中移出
 * @param _id
 */
@SuppressWarnings("deprecation")
private void removeKeepedContacts(long _id){
ContentResolver contentResolver = ContactActivity.this.getContentResolver();
Cursor cusor = null;
@SuppressWarnings("deprecation")
String[] projection = new String[] { Contacts.People._ID, Contacts.People.NAME, Contacts.People.NUMBER };
    cusor = contentResolver.query(Contacts.People.CONTENT_URI, projection, Contacts.People._ID + "=?", new String[] { _id + "" }, Contacts.People.NAME + " ASC");
cusor.moveToFirst();
ContentValues values = new ContentValues();
Uri uri = Uri.withAppendedPath(Contacts.People.CONTENT_URI, cusor.getString(cusor.getColumnIndex(Contacts.People._ID)));
// values.put(Contacts.People.NAME, newName);
values.put(Contacts.People.STARRED, 0);
// values.put(Contacts.Phones.NUMBER, newPhoneNum);
contentResolver.update(uri, values, null, null);
new getKeepedContactsTask().execute((Void)null);
Toast.makeText(ContactActivity.this, ContactActivity.this.getResources().getString(R.string.remove_succeed), Toast.LENGTH_SHORT).show();
}
阅读更多
个人分类: Android学习笔记
想对作者说点什么? 我来说一句

android实现收藏夹

2015年01月13日 1.72MB 下载

wp8 联系人和日历 范例

2014年04月27日 63KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭