Java 类android.provider.ContactsContract.CommonDataKinds.Photo 实例源码
项目:CucumberSync
文件:LocalAddressBook.java
protected void populatePhoto(Contact c) throws RemoteException {
@Cleanup Cursor cursor = providerClient.query(dataURI(),
new String[] { Photo.PHOTO_FILE_ID, Photo.PHOTO },
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), Photo.CONTENT_ITEM_TYPE }, null);
if (cursor != null && cursor.moveToNext()) {
if (!cursor.isNull(0)) {
Uri photoUri = Uri.withAppendedPath(
ContentUris.withAppendedId(RawContacts.CONTENT_URI, c.getLocalID()),
RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
try {
@Cleanup AssetFileDescriptor fd = providerClient.openAssetFile(photoUri, "r");
@Cleanup InputStream is = fd.createInputStream();
c.setPhoto(IOUtils.toByteArray(is));
} catch(IOException ex) {
Log.w(TAG, "Couldn't read high-res contact photo", ex);
}
} else
c.setPhoto(cursor.getBlob(1));
}
}
项目:CucumberSync
文件:LocalAddressBook.java
protected void populateEvents(Contact c) throws RemoteException {
@Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] { CommonDataKinds.Event.TYPE, CommonDataKinds.Event.START_DATE },
Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), CommonDataKinds.Event.CONTENT_ITEM_TYPE }, null);
while (cursor != null && cursor.moveToNext()) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
try {
Date date = formatter.parse(cursor.getString(1));
switch (cursor.getInt(0)) {
case CommonDataKinds.Event.TYPE_ANNIVERSARY:
c.setAnniversary(new Anniversary(date));
break;
case CommonDataKinds.Event.TYPE_BIRTHDAY:
c.setBirthDay(new Birthday(date));
break;
}
} catch (ParseException e) {
Log.w(TAG, "Couldn't parse local birthday/anniversary date", e);
}
}
}
项目:Simplicissimus
文件:Assets.java
public Assets(Context context, long contactId) {
this.context = context;
cursor = context.getContentResolver().query(
Data.CONTENT_URI,
new String[]{Data._ID,
Data.RAW_CONTACT_ID, Data.MIMETYPE, Data.IS_PRIMARY,
Data.IS_SUPER_PRIMARY, Data.DATA_VERSION, Data.DATA1,
Data.DATA2, Data.DATA3, Data.DATA4, Data.DATA5, Data.DATA6,
Data.DATA7, Data.DATA8, Data.DATA9, Data.DATA10, Data.DATA11,
Data.DATA12, Data.DATA13, Data.DATA14, Data.DATA15, Data.SYNC1,
Data.SYNC2, Data.SYNC3, Data.SYNC4, },
Data.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + " IN ( ?, ?, ?, ?, ?, ? )",
new String[]{
String.valueOf(contactId),
Nickname.CONTENT_ITEM_TYPE,
Im.CONTENT_ITEM_TYPE,
Photo.CONTENT_ITEM_TYPE,
},
null);
//cursor.moveToFirst();
columnNames = cursor.getColumnNames();
}
项目:SafeSlinger-Android
文件:ContactAccessorApi5.java
private boolean updatePhoto(ContactStruct contact, String rawContactId, Context ctx) {
// overwrite existing
String[] proj = new String[] {
Photo.RAW_CONTACT_ID, Data.MIMETYPE, Photo.PHOTO
};
String where = Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=? AND " + Photo.PHOTO
+ "!=NULL";
String[] args = new String[] {
rawContactId, Photo.CONTENT_ITEM_TYPE
};
ContentValues values = valuesPhoto(contact);
values.put(Photo.RAW_CONTACT_ID, rawContactId);
return updateDataRow(ctx, proj, where, args, values);
}
项目:osaft
文件:Gatherer.java
/**
* gets the contact photo for the given contact id, if available
*
*/
private void getContactsPhoto(String contact_id) {
Uri photoUri = Data.CONTENT_URI;
String[] projection = new String[] { Photo.PHOTO, Data._ID, Data.CONTACT_ID };
String selection = Data.CONTACT_ID + " = " + contact_id;
Cursor cursor = cr.query(photoUri, projection, selection, null, null);
String filePath = dataPath + "contact_" + contact_id + ".jpg";
try {
while (cursor.moveToNext()) {
byte[] photo = cursor.getBlob(0);
if (photo != null) {
Bitmap photoBitmap = BitmapFactory.decodeByteArray(photo, 0, photo.length);
SDCardHandler.savePicture(filePath, photoBitmap);
}
}
} catch (IOException e) {
view.showIOError("contact picture");
} finally {
cursor.close();
}
}
项目:Contacts
文件:GetContactInfo.java
public static List<ContactEntity> loadContact2(Context context){
List<ContactEntity> contacts=new ArrayList<ContactEntity>();
ContentResolver cr=context.getContentResolver();
String [] projection={Phone.DISPLAY_NAME,Phone.NUMBER,Photo.PHOTO_ID,Phone.CONTACT_ID};
Cursor c=cr.query(Phone.CONTENT_URI, projection, null, null, null);
if(c!=null){
while(c.moveToNext()){
String name=c.getString(0);
String number=c.getString(1);
long contactId=c.getLong(3);
long photoId=c.getLong(2);
Bitmap bitmap=null;
if(photoId>0){
Uri uri=ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
InputStream input=ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
bitmap=BitmapFactory.decodeStream(input);
}
ContactEntity entity=new ContactEntity();
entity.setName(name);
entity.setNumber(number);
entity.setBitmap(bitmap);
contacts.add(entity);
}
}
c.close();
return contacts;
}
项目:android-authenticator
文件:ContactOperations.java
public ContactOperations addAvatar(String pageName, String avatarName) throws IOException {
if (!TextUtils.isEmpty(pageName) && !TextUtils.isEmpty(avatarName)) {
byte[] avatarBuffer = XWikiHttp.downloadImage(pageName, avatarName);
if (avatarBuffer != null) {
mValues.clear();
mValues.put(Photo.PHOTO, avatarBuffer);
mValues.put(Photo.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
addInsertOp();
}
}
return this;
}
项目:android-authenticator
文件:ContactOperations.java
public ContactOperations updateAvatar(String pageName, String avatarName, Uri uri) throws IOException {
if (!TextUtils.isEmpty(pageName) && !TextUtils.isEmpty(avatarName)) {
byte[] avatarBuffer = XWikiHttp.downloadImage(pageName, avatarName);
if (avatarBuffer != null) {
mValues.clear();
mValues.put(Photo.PHOTO, avatarBuffer);
mValues.put(Photo.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
addUpdateOp(uri);
}
}
return this;
}
项目:ntsync-android
文件:ContactOperations.java
/**
* Clears metadata about the original photo file.
*
* @param uri
*/
public ContactOperations clearPhotoMetadata(Uri uri) {
mValues.clear();
mValues.putNull(Photo.SYNC1);
mValues.putNull(Photo.SYNC2);
mValues.putNull(Photo.SYNC3);
addUpdateOp(uri);
return this;
}
项目:ntsync-android
文件:ContactOperations.java
public ContactOperations updatePhotoHash(String hash, int version, Uri uri) {
mValues.clear();
// Hash
mValues.put(Photo.SYNC1, hash);
// Save Sync-Version (this modifications increments the version)
mValues.put(Photo.SYNC2, version);
addUpdateOp(uri);
return this;
}
项目:ntsync-android
文件:ContactManager.java
/**
* Calculate New Hash Value of the current thumbnail.
*
* @param context
* @param rawContact
* @param batchOperation
* @param rawContactId
*/
private static void setNewHashValue(Context context,
BatchOperation batchOperation, long rawContactId) {
// get photo and set new hash and version, because thumbnail will be
// generated from the system.
// Read photo
final ContentResolver resolver = context.getContentResolver();
final Cursor c = resolver.query(DataQuery.CONTENT_URI,
DataQuery.PROJECTION, DataQuery.SELECTION_TYPE,
new String[] { String.valueOf(rawContactId),
Photo.CONTENT_ITEM_TYPE }, null);
try {
while (c.moveToNext()) {
byte[] photo = c.getBlob(DataQuery.COLUMN_PHOTO_IMAGE);
if (photo != null) {
// Generate Hash
Digest digest = new MD5Digest();
byte[] resBuf = new byte[digest.getDigestSize()];
digest.update(photo, 0, photo.length);
digest.doFinal(resBuf, 0);
String hash = Base64.encodeToString(resBuf, Base64.DEFAULT);
int currVersion = c.getInt(DataQuery.COLUMN_VERSION);
int newVersion = currVersion++;
// Set Hash
final ContactOperations contactOp = ContactOperations
.updateExistingContact(rawContactId, true,
batchOperation);
final long id = c.getLong(DataQuery.COLUMN_ID);
final Uri uri = ContentUris.withAppendedId(
Data.CONTENT_URI, id);
contactOp.updatePhotoHash(hash, newVersion, uri);
}
}
} finally {
c.close();
}
}
项目:ntsync-android
文件:ContactManager.java
/**
* Deletes a contact from the platform contacts provider. This method is
* used both for contacts that were deleted locally and then that deletion
* was synced to the server, and for contacts that were deleted on the
* server and the deletion was synced to the client.
*
* @param rawContactId
* the unique Id for this rawContact in contacts provider
*/
private static void deleteContact(Context context, long rawContactId,
BatchOperation batchOperation, String accountName) {
batchOperation.add(ContactOperations.newDeleteCpo(
ContentUris.withAppendedId(RawContacts.CONTENT_URI,
rawContactId), true, true).build());
final ContentResolver resolver = context.getContentResolver();
final Cursor c = resolver.query(DataQuery.CONTENT_URI,
DataQuery.PROJECTION, DataQuery.SELECTION_TYPE,
new String[] { String.valueOf(rawContactId),
Photo.CONTENT_ITEM_TYPE }, null);
while (c.moveToNext()) {
if (!c.isNull(DataQuery.COLUMN_SYNC3)) {
String fileName = c.getString(DataQuery.COLUMN_SYNC3);
// Delete old photo file.
File photoFile = PhotoHelper.getPhotoFile(context, fileName,
accountName);
if (photoFile.exists()) {
boolean deleted = photoFile.delete();
if (!deleted) {
LogHelper.logW(TAG, "Photo File could not be deleted:"
+ photoFile.getAbsolutePath());
}
}
}
}
}
项目:Android-PhotoBook
文件:PhotoGridActivity.java
@Override
protected List doInBackground(String... params) {
Flickr flickr = new Flickr(FLICKR_API_KEY, FLICKR_FORMAT);
List photos = flickr.getPhotoSets().getPhotos(PHOTOSET_ID);
List result = new ArrayList();
totalCount = photos.size();
currentIndex = 0;
for (Photo photo : photos) {
currentIndex++;
List sizes = flickr.getPhotos().getSizes(photo.getId());
String thumbnailUrl = sizes.get(0).getSource();
String mediumUrl = sizes.get(4).getSource();
InputStream inputSteamThumbnail = null, inputStreamMedium=null;
try {
inputStreamThumbnail = new URL(thumbnailUrl).openStream();
inputStreamMedium = new URL(mediumUrl).openStream();
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bitmapThumbnail = BitmapFactory.decodeStream(inputStreamThumbnail);
Bitmap bitmapMedium = BitmapFactory.decodeStream(inputStreamMedium);
result.add(new ImageInfo(photo.getTitle(),bitmapThumbnail ,bitmapMedium ));
publishProgress(currentIndex, totalCount);
}
currentAppData.setImageInfos(result);
return result;
}
项目:SafeSlinger-Android
文件:BaseActivity.java
/**
* Retrieve a user's photo.
*/
protected byte[] getContactPhoto(String contactLookupKey) {
byte[] photo = null;
if (!SafeSlinger.doesUserHavePermission(Manifest.permission.READ_CONTACTS)) {
return photo;
}
if (TextUtils.isEmpty(contactLookupKey)) {
return photo;
}
String where = Data.MIMETYPE + " = ?";
String[] whereParameters = new String[] {
Photo.CONTENT_ITEM_TYPE
};
Uri dataUri = getDataUri(contactLookupKey);
if (dataUri != null) {
Cursor c = getContentResolver().query(dataUri, null, where, whereParameters, null);
if (c != null) {
try {
if (c.moveToFirst()) {
do {
byte[] newphoto = c.getBlob(c.getColumnIndexOrThrow(Photo.PHOTO));
boolean super_primary = (c.getInt(c
.getColumnIndexOrThrow(Photo.IS_SUPER_PRIMARY)) != 0);
if (newphoto != null && (photo == null || super_primary)) {
photo = newphoto;
}
} while (c.moveToNext());
}
} finally {
c.close();
}
}
}
return photo;
}
项目:SafeSlinger-Android
文件:ContactAccessorApi5.java
@Override
public boolean addPhoto(ContactStruct contact, Cursor photos) {
byte[] photo = photos.getBlob(photos.getColumnIndexOrThrow(Photo.PHOTO));
boolean super_primary = (photos.getInt(photos.getColumnIndex(Photo.IS_SUPER_PRIMARY)) != 0);
if (photo != null && isPhotoNew(contact, photo, super_primary)) {
contact.photoBytes = photo;
contact.photoType = null;
return true;
}
return false;
}
项目:SafeSlinger-Android
文件:ContactAccessorApi5.java
private ContentValues valuesPhoto(ContactStruct contact) {
ContentValues val = new ContentValues();
val.put(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
if (contact.photoBytes != null)
val.put(Photo.PHOTO, contact.photoBytes);
return val;
}
项目:silent-text-android
文件:SystemContactRepository.java
@Override
public InputStream getAvatar( String email ) {
Cursor contact = search( email );
try {
if( contact.moveToFirst() ) {
int id = CursorUtils.getInt( contact, Contacts.PHOTO_ID );
Cursor photos = resolver.query( ContentUris.withAppendedId( Data.CONTENT_URI, id ), new String [] {
Photo.PHOTO
}, null, null, null );
try {
if( photos.moveToFirst() ) {
byte [] buffer = photos.getBlob( 0 );
return new ByteArrayInputStream( buffer );
}
} finally {
photos.close();
}
}
} finally {
contact.close();
}
return null;
}
项目:openxface-android
文件:XContactAccessorAPILevel5Impl.java
/**
* 为存在多值的域添加属性
*
* @param contactPropMap
* 包含联系人信息的 map
* @param logicParentField
* 域名
* @param ops
* ContentProviderOperation
*/
private void addMultipleValueProperty(Map<String, Object> contactPropMap,
String logicParentField, ArrayList<ContentProviderOperation> ops) {
String quantityField = generateQuantityFieldOf(logicParentField);
int quantity = (Integer) contactPropMap.get(quantityField);
if (quantity <= 0) {
return;
}
for (int i = 0; i < quantity; i++) {
ContentProviderOperation.Builder builder = ContentProviderOperation
.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(
ContactsContract.Data.RAW_CONTACT_ID, 0);
String contentItemType = LOGIC_FIELD_TO_CONTENT_TYPE_MAP
.get(logicParentField);
builder.withValue(ContactsContract.Data.MIMETYPE, contentItemType);
String commonValueFieldKey = generateSubFieldKey(logicParentField,
i, LOGIC_FIELD_COMMON_VALUE);
Object commonValue = contactPropMap.get(commonValueFieldKey);
// 如果ContactField中的value属性为null,则不保存该ContactField,不然部分手机在保存的时候会抛异常
if (isOnlyCommonSubFieldsIncluded(logicParentField)
&& null == commonValue) {
continue;
}
if (logicParentField == LOGIC_FIELD_PHOTOS) {
builder.withValue(ContactsContract.Data.IS_SUPER_PRIMARY, 1)
.withValue(Photo.PHOTO, commonValue);
} else {
setSubFieldValueToBuilder(builder, contactPropMap,
logicParentField, i);
}
ops.add(builder.build());
}
}
项目:phoneContact
文件:ContactDAO.java
/**
* �����ϵ��
*
* @param contact
* ��ϵ��ʵ�����
* @param groupId
* ���
*/
public boolean addContact1(SortEntry contact, int groupId) {
if (TextUtils.isEmpty(contact.mName)) {
Toast.makeText(context, "����������", Toast.LENGTH_LONG).show();
return false;
}
ContentValues values = new ContentValues();
Uri rawContactUri = context.getContentResolver().insert(
RawContacts.CONTENT_URI, values);
int rawContactId = (int) ContentUris.parseId(rawContactUri);
// ��data���������
if (contact.mName != "") {
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
values.put(StructuredName.GIVEN_NAME, contact.mName);
context.getContentResolver().insert(
ContactsContract.Data.CONTENT_URI,values);
}
// ��data�в���绰����
if (contact.mNum != "") {
values.clear();
String[] numbers = Tools.getPhoneNumber(contact.mNum);
for (int i = 0; i < numbers.length; i++) {
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, numbers[i]);
values.put(Phone.TYPE, Phone.TYPE_MOBILE);
context.getContentResolver().insert(
ContactsContract.Data.CONTENT_URI, values);
}
}
// ���ͷ��
if (contact.contactPhoto != null) {
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
values.put(Photo.PHOTO,
ImageConvert.bitmapToByte(contact.contactPhoto));
context.getContentResolver().insert(
ContactsContract.Data.CONTENT_URI, values);
}
// // ��ӵ�ַ
// if (contact.getAddress() != "") {
// values.clear();
// values.put(Data.RAW_CONTACT_ID, rawContactId);
// values.put(Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE);
// values.put(SipAddress.CONTENT_ITEM_TYPE, contact.getAddress());
// context.getContentResolver().insert(
// ContactsContract.Data.CONTENT_URI, values);
// }
// // �������
// if (contact.getEmail() != "") {
// values.clear();
// values.put(Data.RAW_CONTACT_ID, rawContactId);
// values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
// values.put(Email.CONTENT_ITEM_TYPE, contact.getEmail());
// context.getContentResolver().insert(
// ContactsContract.Data.CONTENT_URI, values);
// }
if (groupId != 0) {
new GroupDAO(context).addMemberToGroup(rawContactId, groupId);
}
return true;
}
项目:phoneContact
文件:ContactDAO.java
/**
* ������ϵ��
*
* @param rawContactId
* ��ϵ��id
*/
public void updataCotact(long rawContactId, SortEntry contact,
int old_groupID) {
ContentValues values = new ContentValues();
// ��������
values.put(StructuredName.GIVEN_NAME, contact.mName);
context.getContentResolver().update(
ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(rawContactId),
StructuredName.CONTENT_ITEM_TYPE });
// ���µ绰
if (contact.mNum != "") {
values.clear();
String[] numbers = Tools.getPhoneNumber(contact.mNum);
for (int i = 0; i < numbers.length; i++) {
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, numbers[i]);
values.put(Phone.TYPE, Phone.TYPE_MOBILE);
// context.getContentResolver().insert(
// ContactsContract.Data.CONTENT_URI, values);
context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID+"=? and "+Data.MIMETYPE+"=?",
new String[]{String.valueOf(rawContactId),Phone.CONTENT_ITEM_TYPE});
}
}
// ����ͷ��
values.clear();
if (contact.contactPhoto != null) {
values.put(ContactsContract.CommonDataKinds.Photo.PHOTO,
ImageConvert.bitmapToByte(contact.contactPhoto));
context.getContentResolver().update(
ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + " =?",
new String[] { String.valueOf(rawContactId),
Photo.CONTENT_ITEM_TYPE });
}
// ����Ⱥ��
if (contact.groupId != 0) {
values.clear();
values.put(
ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID,
contact.groupId);
context.getContentResolver().update(
ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + " =?",
new String[] { String.valueOf(rawContactId),
GroupMembership.CONTENT_ITEM_TYPE });
} else {
new GroupDAO(context).deleteMemberFromGroup(
Integer.parseInt(contact.mID), old_groupID);
}
}
项目:phoneContact
文件:ContactDAO.java
/**
* ������ϵ�� ��ʼû��ͷ�����ϵ��
*
* @param rawContactId
* ��ϵ��id
*/
public void updataCotactNoPhoto(long rawContactId, SortEntry contact,
int old_groupID) {
ContentValues values = new ContentValues();
// ��������
values.put(StructuredName.GIVEN_NAME, contact.mName);
context.getContentResolver().update(
ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(rawContactId),
StructuredName.CONTENT_ITEM_TYPE });
// ���µ绰
if (contact.mNum != "") {
values.clear();
String[] numbers = Tools.getPhoneNumber(contact.mNum);
for (int i = 0; i < numbers.length; i++) {
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, numbers[i]);
values.put(Phone.TYPE, Phone.TYPE_MOBILE);
context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID+"=? and "+Data.MIMETYPE+"=?",
new String[]{String.valueOf(rawContactId),Phone.CONTENT_ITEM_TYPE});
}
}
// ���ͷ��
if (contact.contactPhoto != null) {
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
values.put(Photo.PHOTO,
ImageConvert.bitmapToByte(contact.contactPhoto));
context.getContentResolver().insert(
ContactsContract.Data.CONTENT_URI, values);
}
// ����Ⱥ��
if (contact.groupId != 0) {
values.clear();
values.put(
ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID,
contact.groupId);
context.getContentResolver().update(
ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + " =?",
new String[] { String.valueOf(rawContactId),
GroupMembership.CONTENT_ITEM_TYPE });
} else {
new GroupDAO(context).deleteMemberFromGroup(
Integer.parseInt(contact.mID), old_groupID);
}
}
项目:phoneContact
文件:ContactDAO.java
/**
* ������ϵ�� ����ǰû��Ⱥ�����ϵ��
*
* @param rawContactId
* ��ϵ��id
*/
public void updataCotactNoGroup(long rawContactId, SortEntry contact) {
ContentValues values = new ContentValues();
// ��������
values.put(StructuredName.GIVEN_NAME, contact.mName);
context.getContentResolver().update(
ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(rawContactId),
StructuredName.CONTENT_ITEM_TYPE });
// ���µ绰
if (contact.mNum != "") {
values.clear();
String[] numbers = Tools.getPhoneNumber(contact.mNum);
for (int i = 0; i < numbers.length; i++) {
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, numbers[i]);
values.put(Phone.TYPE, Phone.TYPE_MOBILE);
context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID+"=? and "+Data.MIMETYPE+"=?",
new String[]{String.valueOf(rawContactId),Phone.CONTENT_ITEM_TYPE});
}
}
// ����ͷ��
if (contact.contactPhoto != null) {
values.clear();
values.put(ContactsContract.CommonDataKinds.Photo.PHOTO,
ImageConvert.bitmapToByte(contact.contactPhoto));
context.getContentResolver().update(
ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + " =?",
new String[] { String.valueOf(rawContactId),
Photo.CONTENT_ITEM_TYPE });
}
// ��ӵ�Ⱥ��
if (contact.groupId != 0) {
new GroupDAO(context).addMemberToGroup(
Integer.parseInt(contact.mID), contact.groupId);
}
}
项目:phoneContact
文件:ContactDAO.java
/**
* ������ϵ�� ����ǰû��ͷ��Ⱥ�����ϵ��
*
* @param rawContactId
* ��ϵ��id
*/
public void updataCotactNoG_Photo(long rawContactId, SortEntry contact) {
ContentValues values = new ContentValues();
// ��������
values.put(StructuredName.GIVEN_NAME, contact.mName);
context.getContentResolver().update(
ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(rawContactId),
StructuredName.CONTENT_ITEM_TYPE });
// ���µ绰
if (contact.mNum != "") {
values.clear();
String[] numbers = Tools.getPhoneNumber(contact.mNum);
for (int i = 0; i < numbers.length; i++) {
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, numbers[i]);
values.put(Phone.TYPE, Phone.TYPE_MOBILE);
context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID+"=? and "+Data.MIMETYPE+"=?",
new String[]{String.valueOf(rawContactId),Phone.CONTENT_ITEM_TYPE});
}
}
// ���ͷ��
if (contact.contactPhoto != null) {
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
values.put(Photo.PHOTO,
ImageConvert.bitmapToByte(contact.contactPhoto));
context.getContentResolver().insert(
ContactsContract.Data.CONTENT_URI, values);
}
// ��ӵ�Ⱥ��
if (contact.groupId != 0) {
new GroupDAO(context).addMemberToGroup(
Integer.parseInt(contact.mID), contact.groupId);
}
}
项目:CucumberSync
文件:LocalAddressBook.java
protected Builder buildPhoto(Builder builder, byte[] photo) {
return builder
.withValue(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE)
.withValue(Photo.PHOTO, photo);
}
项目:SafeSlinger-Android
文件:ContactAccessorApi5.java
@Override
public String[] getProjPhoto() {
return new String[] {
Photo.MIMETYPE, Photo.PHOTO, Photo.IS_PRIMARY, Photo.IS_SUPER_PRIMARY
};
}
项目:SafeSlinger-Android
文件:ContactAccessorApi5.java
@Override
public String getQueryPhoto() {
return Photo.MIMETYPE + " = " + DatabaseUtils.sqlEscapeString("" + Photo.CONTENT_ITEM_TYPE);
}
项目:cordova-images-browser
文件:ImagesBrowser.java
@SuppressLint("NewApi")
public JSONArray getContacts(CordovaInterface cordova) throws JSONException{
JSONArray result = new JSONArray();
Cursor datapoints = new CursorLoader(cordova.getActivity(),
ContactsContract.Data.CONTENT_URI,
null,
null,
null,
ContactsContract.Data.CONTACT_ID
).loadInBackground();
int contact_id_idx = datapoints.getColumnIndex(ContactsContract.Data.CONTACT_ID);
int mime_type_idx = datapoints.getColumnIndex(ContactsContract.Data.MIMETYPE);
String currentId = "";
String versionHash = "";
JSONObject currentContact = new JSONObject();
JSONArray items = new JSONArray();
while(datapoints.moveToNext()){
String id = datapoints.getString(contact_id_idx);
if(!id.equals(currentId)){
// new ID, store contact, create next
if(items.length() > 0 && !currentId.equals("")){
currentContact.put("localVersion", versionHash);
currentContact.put("datapoints", items);
result.put(currentContact);
}
currentContact = new JSONObject();
currentContact.put("localId", id);
items = new JSONArray();
currentId = id;
versionHash = "";
}
String type = datapoints.getString(mime_type_idx);
if(type.equals(Phone.CONTENT_ITEM_TYPE)){
items.put(handleBaseColumns(datapoints, false));
versionHash += "-" + datapoints.getInt(datapoints.getColumnIndex(Data.DATA_VERSION));
}else if(type.equals(Email.CONTENT_ITEM_TYPE)){
items.put(handleBaseColumns(datapoints, true));
versionHash += "-" +datapoints.getInt(datapoints.getColumnIndex(Data.DATA_VERSION));
}else if(type.equals(StructuredName.CONTENT_ITEM_TYPE)){
handleName(currentContact, datapoints);
versionHash += "-" +datapoints.getInt(datapoints.getColumnIndex(Data.DATA_VERSION));
}else if(type.equals(Photo.CONTENT_ITEM_TYPE)){
// byte[] blob = datapoints.getBlob(datapoints.getColumnIndex(Photo.PHOTO));
// currentContact.put("photo", Base64.encode(blob));
}
}
if(!currentId.equals("")){
currentContact.put("localVersion", versionHash);
currentContact.put("datapoints", items);
result.put(currentContact);
}
return result;
}
项目:openxface-android
文件:XContactAccessorAPILevel5Impl.java
/**
* 将cursor中当前指向的item中的联系人信息存放到hash表中
* 注:仅在cursor中当前指向的item数据为MultipleValueField的子属性数据时使用<br/>
* (如:addresses, organizations,urls的子属性集)
*/
private void multipleValueFieldQuery(Map<String, Object> contactsMap,
Cursor cursor, String logicParentField) {
String quantityField = generateQuantityFieldOf(logicParentField);
int quantity = getQuantityValue(contactsMap, quantityField);
List<String> logicSubFields = getLogicContactSubFieldsOf(logicParentField);
Map<String, String> subFieldsMap = getContactSubFieldsMapOf(logicParentField);
for (String subField : logicSubFields) {
String key = generateSubFieldKey(logicParentField, quantity,
subField);
if (LOGIC_FIELD_COMMON_ID.equals(subField)) {
contactsMap.put(key, cursor.getString(cursor
.getColumnIndex(BaseColumns._ID)));
} else if (LOGIC_FIELD_COMMON_PREF.equals(subField)) {
contactsMap.put(key, false); // Android没有存储pref属性
} else if (LOGIC_FIELD_COMMON_TYPE.equals(subField)) {
if (LOGIC_FIELD_PHOTOS.equals(logicParentField)) {
contactsMap.put(key, NATIVE_PHOTO_TYPE_VALUE);
} else {
int nativeTypeValue = cursor.getInt(cursor
.getColumnIndex(subFieldsMap.get(subField)));
String logicTypeValue = getLogicTypeValue(logicParentField,
nativeTypeValue);
contactsMap.put(key, logicTypeValue);
}
} else if (LOGIC_FIELD_COMMON_VALUE.equals(subField)
&& LOGIC_FIELD_PHOTOS.equals(logicParentField)) {
Uri person = ContentUris.withAppendedId(
ContactsContract.Contacts.CONTENT_URI, (new Long(
getContactId(cursor))));
Uri photoUri = Uri.withAppendedPath(person,
ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
contactsMap.put(key, photoUri.toString());
} else {
Object fieldValue = cursor.getString(cursor
.getColumnIndex(subFieldsMap.get(subField)));
contactsMap.put(key, fieldValue);
}
}
contactsMap.put(quantityField, quantity + 1);
}