项目:q-mail
文件:RecipientLoader.java
private boolean fillContactDataFromNameAndEmail(String query,List<Recipient> recipients,Map<String,Recipient> recipientMap) {
query = "%" + query + "%";
Uri queryUri = Email.CONTENT_URI;
String selection = Contacts.disPLAY_NAME_PRIMARY + " LIKE ? " +
" OR (" + Email.ADDRESS + " LIKE ? AND " + Data.MIMETYPE + " = '" + Email.CONTENT_ITEM_TYPE + "')";
String[] selectionArgs = { query,query };
Cursor cursor = contentResolver.query(queryUri,PROJECTION,selection,selectionArgs,SORT_ORDER);
if (cursor == null) {
return false;
}
fillContactDataFromCursor(cursor,recipients,recipientMap);
return true;
}
项目:amap
文件:AddressServiceImpl.java
private static void addContactToGroup(ContentResolver mResolver,int contactId,int groupId)
{
// judge whether the contact has been in the group
boolean b1 = ifExistContactInGroup(mResolver,contactId,groupId);
if (b1)
{
// the contact has been in the group
return;
}
else
{
ContentValues values = new ContentValues();
values.put(ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID,contactId);
values.put(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID,groupId);
values.put(ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE,ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE);
mResolver.insert(ContactsContract.Data.CONTENT_URI,values);
}
}
项目:amap
文件:AddressServiceImpl.java
private static boolean ifExistContactInGroup(ContentResolver mResolver,int groupId)
{
String where =
Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE + "' AND "
+ Data.DATA1 + " = '" + groupId + "' AND " + Data.RAW_CONTACT_ID + " = '" + contactId + "'";
Cursor markCursor =
mResolver.query(ContactsContract.Data.CONTENT_URI,new String[] {ContactsContract.Data.disPLAY_NAME},where,null,null);
if (markCursor.movetoFirst())
{
return true;
}
else
{
return false;
}
}
项目:K9-MailClient
文件:RecipientLoader.java
private void fillContactDataFromQuery(String query,Recipient> recipientMap) {
ContentResolver contentResolver = getContext().getContentResolver();
query = "%" + query + "%";
Uri queryUri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
String selection = Contacts.disPLAY_NAME_PRIMARY + " LIKE ? " +
" OR (" + Email.ADDRESS + " LIKE ? AND " + Data.MIMETYPE + " = '" + Email.CONTENT_ITEM_TYPE + "')";
String[] selectionArgs = { query,SORT_ORDER);
if (cursor == null) {
return;
}
fillContactDataFromCursor(cursor,recipientMap);
if (observerContact != null) {
observerContact = new ForceLoadContentObserver();
contentResolver.registerContentObserver(queryUri,false,observerContact);
}
}
项目:NikiRun
文件:RunSetSlidePageActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_runset_screenslide_pager);
setTitle("跑步设定");
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,R.layout.list_item1,Data);
ListView listView = (ListView) findViewById(R.id.runset_listview);
listView.setAdapter(arrayAdapter);
listView.setonItemClickListener(this);
// Instantiate a ViewPager and a PagerAdapter.
mRunSetAdapter = new RunSetPagerAdapter(this);
mPager = (ViewPager) findViewById(R.id.runset_pager);
// mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mRunSetAdapter);
mBeginRunButton = (Button) findViewById(R.id.begin_run);
mBeginRunButton.setonClickListener(this);
}
项目:zone-sdk
文件:ContactsHelper.java
/**
* 删除单个数据,会直接删除是这个名字的人的所有信息
*
* @param name 用户的姓名
* @return 是否删除成功
*/
public boolean delete(String name) {
try {
//根据姓名求id
Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
//查询到name=“name”的集合
Cursor cursor = mResolver.query(uri,new String[]{Data._ID},"display_name=?",new String[]{name},null);
if (cursor.movetoFirst()) {
int id = cursor.getInt(0);
//根据id删除data中的相应数据
mResolver.delete(uri,new String[]{name});
uri = Uri.parse("content://com.android.contacts/data");
mResolver.delete(uri,"raw_contact_id=?",new String[]{id + ""});
return true;
}
} catch (Exception e) {
e.printstacktrace();
}
return false;
}
项目:zone-sdk
文件:ContactsHelper.java
/**
* 修改联系人数据
*/
public boolean update(String name,String phoneNumber) {
try {
//根据姓名求id,再根据id删除
Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
Cursor cursor = mResolver.query(uri,null);
if (cursor.movetoFirst()) {
int id = cursor.getInt(0);
Uri mUri = Uri.parse("content://com.android.contacts/data");//对data表的所有数据操作
ContentValues values = new ContentValues();
values.put("data1",phoneNumber);
mResolver.update(mUri,values,"mimetype=? and raw_contact_id=?",new String[]{"vnd.android.cursor.item/phone_v2",id + ""});
return true;
}
} catch (Exception e) {
e.printstacktrace();
}
return false;
}
项目:NonViewUtils
文件:ContactsHelper.java
/**
* 删除单个数据,会直接删除是这个名字的人的所有信息
*
* @param name 用户的姓名
* @return 是否删除成功
*/
public boolean delete(String name) {
try {
//根据姓名求id
Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
ContentResolver resolver = mContext.getContentResolver();
//查询到name=“name”的集合
Cursor cursor = resolver.query(uri,null);
if (cursor.movetoFirst()) {
int id = cursor.getInt(0);
//根据id删除data中的相应数据
resolver.delete(uri,new String[]{name});
uri = Uri.parse("content://com.android.contacts/data");
resolver.delete(uri,new String[]{id + ""});
return true;
}
} catch (Exception e) {
e.printstacktrace();
}
return false;
}
项目:NonViewUtils
文件:ContactsHelper.java
/**
* 修改联系人数据
*/
public boolean update(String name,再根据id删除
Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
ContentResolver resolver = mContext.getContentResolver();
Cursor cursor = resolver.query(uri,null);
if (cursor.movetoFirst()) {
int id = cursor.getInt(0);
Uri mUri = Uri.parse("content://com.android.contacts/data");//对data表的所有数据操作
ContentResolver mResolver = mContext.getContentResolver();
ContentValues values = new ContentValues();
values.put("data1",id + ""});
return true;
}
} catch (Exception e) {
e.printstacktrace();
}
return false;
}
项目:q-mail
文件:RecipientLoader.java
private Cursor getNicknameCursor(String nickname) {
nickname = "%" + nickname + "%";
Uri queryUriForNickname = ContactsContract.Data.CONTENT_URI;
return contentResolver.query(queryUriForNickname,PROJECTION_NICKNAME,ContactsContract.CommonDataKinds.Nickname.NAME + " LIKE ? AND " +
Data.MIMETYPE + " = ?",new String[] { nickname,ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE },null);
}
项目:q-mail
文件:RecipientLoader.java
@SuppressWarnings("ConstantConditions")
private boolean fillContactDataFromNickname(String nickname,Recipient> recipientMap) {
boolean hasContact = false;
Uri queryUri = Email.CONTENT_URI;
Cursor nicknameCursor = getNicknameCursor(nickname);
if (nicknameCursor == null) {
return hasContact;
}
try {
while (nicknameCursor.movetoNext()) {
String id = nicknameCursor.getString(INDEX_CONTACT_ID_FOR_NICKNAME);
String selection = ContactsContract.Data.CONTACT_ID + " = ?";
Cursor cursor = contentResolver
.query(queryUri,new String[] { id },SORT_ORDER);
String contactNickname = nicknameCursor.getString(INDEX_NICKNAME);
fillContactDataFromCursor(cursor,recipientMap,contactNickname);
hasContact = true;
}
} finally {
nicknameCursor.close();
}
return hasContact;
}
项目:amap
文件:AddressServiceImpl.java
public static void AddContact(ContentResolver mResolver,String name,String number,String groupName)
{
Log.i("hoperun","name= " + name + ";number=" + number);
if (!queryFromContact(mResolver,name,number))
{
ContentValues values = new ContentValues();
// 首先向RawContacts.CONTENT_URI执行一个空值插入,目的是获取系统返回的rawContactId
Uri rawContactUri = mResolver.insert(RawContacts.CONTENT_URI,values);
if (rawContactUri != null)
{
long rawContactId = ContentUris.parseId(rawContactUri);
// 往data表插入姓名数据
values.clear();
values.put(Data.RAW_CONTACT_ID,rawContactId);
values.put(Data.MIMETYPE,Structuredname.CONTENT_ITEM_TYPE);// 内容类型
values.put(Structuredname.GIVEN_NAME,name);
mResolver.insert(ContactsContract.Data.CONTENT_URI,values);
// 往data表插入电话数据
values.clear();
values.put(Data.RAW_CONTACT_ID,Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER,number);
values.put(Phone.TYPE,Phone.TYPE_MOBILE);
mResolver.insert(ContactsContract.Data.CONTENT_URI,values);
}
else
{
Log.i("hoperun","name= " + name + ";number=" + number);
}
}
else
{
Log.i("hoperun","repeat name= " + name + ";number=" + number);
}
}
项目:SmartChart
文件:CommonUtils.java
/**
* 往手机通讯录插入联系人
*
* @param ct
* @param name
* @param tel
* @param email
*/
public static void insertContact(Context ct,String tel,String email) {
ContentValues values = new ContentValues();
// 首先向RawContacts.CONTENT_URI执行一个空值插入,目的是获取系统返回的rawContactId
Uri rawContactUri = ct.getContentResolver().insert(RawContacts.CONTENT_URI,values);
long rawContactId = ContentUris.parseId(rawContactUri);
// 往data表入姓名数据
if (!TextUtils.isEmpty(tel)) {
values.clear();
values.put(Data.RAW_CONTACT_ID,rawContactId);
values.put(Data.MIMETYPE,Structuredname.CONTENT_ITEM_TYPE);// 内容类型
values.put(Structuredname.GIVEN_NAME,name);
ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI,values);
}
// 往data表入电话数据
if (!TextUtils.isEmpty(tel)) {
values.clear();
values.put(Data.RAW_CONTACT_ID,Phone.CONTENT_ITEM_TYPE);// 内容类型
values.put(Phone.NUMBER,tel);
values.put(Phone.TYPE,Phone.TYPE_MOBILE);
ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI,values);
}
// 往data表入Email数据
if (!TextUtils.isEmpty(email)) {
values.clear();
values.put(Data.RAW_CONTACT_ID,Email.CONTENT_ITEM_TYPE);// 内容类型
values.put(Email.DATA,email);
values.put(Email.TYPE,Email.TYPE_WORK);
ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI,values);
}
}
项目:android-testing-runtime-permissions
文件:MainActivity.java
@Override
public Loader<Cursor> onCreateLoader(int id,Bundle args) {
String[] columns = {Phone._ID,Phone.disPLAY_NAME_PRIMARY,Phone.DATA};
String selection = Data.MIMETYPE + " = '" + Phone.CONTENT_ITEM_TYPE + "'";
String orderBy = Phone.disPLAY_NAME_PRIMARY + " ASC";
return new CursorLoader(this,Phone.CONTENT_URI,columns,orderBy);
}
项目:AndroidBase
文件:ContactsHelper.java
/**
* 添加一个联系人数据
*
* @return 返回true表示添加成功,false表示失败
*/
public boolean insert(String name,String phoneNumber) {
//根据号码找数据,如果存在则不添加
if (getNameByPhoneNumber(phoneNumber) == null) {
//插入raw_contacts表,并获取_id属性
Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
ContentResolver resolver = mContext.getContentResolver();
ContentValues values = new ContentValues();
long contact_id = ContentUris.parseId(resolver.insert(uri,values));
//插入data表
uri = Uri.parse("content://com.android.contacts/data");
//添加姓名
values.put("raw_contact_id",contact_id);
values.put(Data.MIMETYPE,"vnd.android.cursor.item/name");
values.put("data2",name);
resolver.insert(uri,values);
values.clear();
//添加手机号码
values.put("raw_contact_id","vnd.android.cursor.item/phone_v2");
values.put("data2","2"); //2表示手机
values.put("data1",phoneNumber);
resolver.insert(uri,values);
values.clear();
return true;
} else {
return false;
}
}
项目:AndroidBase
文件:ContactsHelper.java
/**
* 删除单个数据,会直接删除是这个名字的人的所有信息
*
* @param name 用户的姓名
* @return 是否删除成功
*/
public boolean delete(String name) {
Cursor cursor = null;
try {
//根据姓名求id
Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
ContentResolver resolver = mContext.getContentResolver();
//查询到name=“name”的集合
cursor = resolver.query(uri,null);
if (cursor != null) {
if (cursor.movetoFirst()) {
int id = cursor.getInt(0);
//根据id删除data中的相应数据
resolver.delete(uri,new String[]{name});
uri = Uri.parse("content://com.android.contacts/data");
resolver.delete(uri,new String[]{id + ""});
return true;
}
}
} catch (Exception e) {
e.printstacktrace();
}finally {
if (cursor != null) {
cursor.close();
}
}
return false;
}
项目:AndroidBase
文件:ContactsHelper.java
/**
* 修改联系人数据
*/
public boolean update(String name,String phoneNumber) {
Cursor cursor = null;
try {
//根据姓名求id,再根据id删除
Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
ContentResolver resolver = mContext.getContentResolver();
cursor = resolver.query(uri,null);
if (cursor != null) {
if (cursor.movetoFirst()) {
int id = cursor.getInt(0);
Uri mUri = Uri.parse("content://com.android.contacts/data");//对data表的所有数据操作
ContentResolver mResolver = mContext.getContentResolver();
ContentValues values = new ContentValues();
values.put("data1",phoneNumber);
mResolver.update(mUri,id + ""});
return true;
}
}
} catch (Exception e) {
e.printstacktrace();
}finally {
if (cursor != null) {
cursor.close();
}
}
return false;
}
项目:zone-sdk
文件:ContactsHelper.java
/**
* 添加一个联系人数据
*
* @return 返回true表示添加成功,false表示失败
*/
public boolean insert(String name,String phoneNumber) {
//根据号码找数据,如果存在则不添加
if (getNameByPhoneNumber(phoneNumber) == null) {
//插入raw_contacts表,并获取_id属性
Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
ContentValues values = new ContentValues();
long contact_id = ContentUris.parseId(mResolver.insert(uri,name);
mResolver.insert(uri,phoneNumber);
mResolver.insert(uri,values);
values.clear();
return true;
} else {
return false;
}
}
项目:NonViewUtils
文件:ContactsHelper.java
项目:amap
文件:AddressServiceImpl.java
public static boolean queryFromContact(ContentResolver mResolver,String number)
{
ContentValues values = new ContentValues();
// 首先向RawContacts.CONTENT_URI执行一个空值插入,目的是获取系统返回的rawContactId
String where = Data.MIMETYPE + "=? and " + Structuredname.GIVEN_NAME + "=?";
Cursor mCursor =
mResolver.query(ContactsContract.Data.CONTENT_URI,new String[] {
Structuredname.CONTENT_ITEM_TYPE,name},null);
System.out.println("--------------------phone--------------------1");
if (mCursor != null)
{
while (mCursor.movetoNext())
{
String rowId = mCursor.getString(mCursor.getColumnIndex(Data.RAW_CONTACT_ID));
String phoneWhere = Data.MIMETYPE + "=? and " + Phone.NUMBER + "=?";
Cursor mPhoneCur =
mResolver.query(ContactsContract.Data.CONTENT_URI,phoneWhere,new String[] {
Phone.CONTENT_ITEM_TYPE,number},null);
if (mPhoneCur != null)
{
while (mPhoneCur.movetoNext())
{
String phoneRowId = mPhoneCur.getString(mPhoneCur.getColumnIndex(Data.RAW_CONTACT_ID));
if (rowId.equals(phoneRowId))
{
mPhoneCur.close();
mCursor.close();
return true;
}
}
}
if (mPhoneCur != null)
{
mPhoneCur.close();
}
}
}
if (mCursor != null)
{
mCursor.close();
}
return false;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。