本文整理汇总了Java中android.provider.ContactsContract.Data类的典型用法代码示例。如果您正苦于以下问题:Java Data类的具体用法?Java Data怎么用?Java Data使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Data类属于android.provider.ContactsContract包,在下文中一共展示了Data类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAddContactIntent
import android.provider.ContactsContract.Data; //导入依赖的package包/类
@Override
public Intent getAddContactIntent(String displayName, String csipUri) {
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT, Contacts.CONTENT_URI);
intent.setType(Contacts.CONTENT_ITEM_TYPE);
if (!TextUtils.isEmpty(displayName)) {
intent.putExtra(Insert.NAME, displayName);
}
if (!TextUtils.isEmpty(csipUri)) {
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
ContentValues csipProto = new ContentValues();
csipProto.put(Data.MIMETYPE, CommonDataKinds.Im.CONTENT_ITEM_TYPE);
csipProto.put(CommonDataKinds.Im.PROTOCOL, CommonDataKinds.Im.PROTOCOL_CUSTOM);
csipProto.put(CommonDataKinds.Im.CUSTOM_PROTOCOL, SipManager.PROTOCOL_CSIP);
csipProto.put(CommonDataKinds.Im.DATA, SipUri.getCanonicalSipContact(csipUri, false));
data.add(csipProto);
intent.putParcelableArrayListExtra(Insert.DATA, data);
}
return intent;
}
示例2: getWhatsAppNumber
import android.provider.ContactsContract.Data; //导入依赖的package包/类
String getWhatsAppNumber(String name) {
Cursor cursor = this.context.getContentResolver().query(Data.CONTENT_URI, new String[]{"data3"}, "display_name=? AND mimetype=?", new String[]{name, WHATSAPP_CONTACT_MIMETYPE}, null);
String phoneNumber = null;
int foundContacts = 0;
while (cursor.moveToNext()) {
foundContacts++;
if (foundContacts > 1) {
Log.d(TAG, "Found more than one WhatsApp contact -- skipping WhatsApp deeplinking");
phoneNumber = null;
break;
}
phoneNumber = cursor.getString(cursor.getColumnIndex("data3"));
Log.d(TAG, "Found WhatsApp # " + phoneNumber + " for " + name);
}
cursor.close();
return phoneNumber;
}
示例3: getGroupMembership
import android.provider.ContactsContract.Data; //导入依赖的package包/类
public List<ContactData> getGroupMembership(Context context, long groupId) {
LinkedList<ContactData> contacts = new LinkedList<ContactData>();
Cursor groupMembership = null;
try {
String selection = ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + " = ? AND " +
ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE + " = ?";
String[] args = new String[] {groupId+"",
ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE};
groupMembership = context.getContentResolver().query(Data.CONTENT_URI, null, selection, args, null);
while (groupMembership != null && groupMembership.moveToNext()) {
String displayName = groupMembership.getString(groupMembership.getColumnIndexOrThrow(Data.DISPLAY_NAME));
long contactId = groupMembership.getLong(groupMembership.getColumnIndexOrThrow(Data.CONTACT_ID));
contacts.add(getContactData(context, displayName, contactId));
}
} finally {
if (groupMembership != null)
groupMembership.close();
}
return contacts;
}
示例4: onCreateLoader
import android.provider.ContactsContract.Data; //导入依赖的package包/类
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
// Choose the proper action
switch (id) {
case DETAILS_QUERY_ID:
// Assigns the selection parameter
mSelectionArgs[0] = mLookupKey;
Log.i("Info","Key"+mLookupKey);
// Starts the query
CursorLoader mLoader =
new CursorLoader(
getActivity(),
Data.CONTENT_URI,
PROJECTION,
SELECTION,
mSelectionArgs,
SORT_ORDER
);
return mLoader;
}
return null;
}
示例5: getGroupIdByContactId
import android.provider.ContactsContract.Data; //导入依赖的package包/类
/**
* ������ϵ��ID��ȡ��ϵ������Ⱥ��
*
* @param contactId
* ��ϵ��ID
* @return
*/
public int getGroupIdByContactId(int contactId) {
Uri uri = ContactsContract.Data.CONTENT_URI;
String[] RAW_PROJECTION = new String[] { Data.MIMETYPE, Data.DATA1 };
Cursor cursor = context.getContentResolver().query(uri, RAW_PROJECTION,
Data.RAW_CONTACT_ID + "=?", new String[] { contactId + "" },
null);
int groupId = 0;
while (cursor.moveToNext()) {
String mime = cursor.getString(cursor.getColumnIndex("mimetype"));
if ("vnd.android.cursor.item/group_membership".equals(mime)) {
groupId = cursor.getInt(cursor.getColumnIndex("data1"));
}
}
cursor.close();
return groupId;
}
示例6: doInBackground
import android.provider.ContactsContract.Data; //导入依赖的package包/类
@Override
protected Void doInBackground(Long... ids) {
String[] projection = new String[] {Phone.DISPLAY_NAME, Phone.TYPE, Phone.NUMBER, Phone.LABEL};
long contactId = ids[0];
final Cursor phoneCursor = getActivity().getContentResolver().query(
Phone.CONTENT_URI,
projection,
Data.CONTACT_ID + "=?",
new String[]{String.valueOf(contactId)},
null);
if(phoneCursor != null && phoneCursor.moveToFirst() && phoneCursor.getCount() == 1) {
final int contactNumberColumnIndex = phoneCursor.getColumnIndex(Phone.NUMBER);
mPhoneNumber = phoneCursor.getString(contactNumberColumnIndex);
int type = phoneCursor.getInt(phoneCursor.getColumnIndexOrThrow(Phone.TYPE));
mPhoneLabel = phoneCursor.getString(phoneCursor.getColumnIndex(Phone.LABEL));
mPhoneLabel = Phone.getTypeLabel(getResources(), type, mPhoneLabel).toString();
phoneCursor.close();
}
return null;
}
示例7: createAddressContentValues
import android.provider.ContactsContract.Data; //导入依赖的package包/类
private ContentValues createAddressContentValues(final JSONObject address, final int typeConstant,
final String type) throws JSONException {
ContentValues contentValues = new ContentValues();
contentValues.put(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE);
contentValues.put(StructuredPostal.STREET, address.optString("streetAddress"));
contentValues.put(StructuredPostal.CITY, address.optString("locality"));
contentValues.put(StructuredPostal.REGION, address.optString("region"));
contentValues.put(StructuredPostal.POSTCODE, address.optString("postalCode"));
contentValues.put(StructuredPostal.COUNTRY, address.optString("countryName"));
if (type != null) {
contentValues.put(StructuredPostal.TYPE, typeConstant);
// If a custom type, add a label
if (typeConstant == BaseTypes.TYPE_CUSTOM) {
contentValues.put(StructuredPostal.LABEL, type);
}
}
if (address.has("pref")) {
contentValues.put(Data.IS_SUPER_PRIMARY, address.getBoolean("pref") ? 1 : 0);
}
return contentValues;
}
示例8: createContentValues
import android.provider.ContactsContract.Data; //导入依赖的package包/类
private ContentValues createContentValues(final String mimeType, final String value, final int typeConstant,
final String type, final boolean preferredValue) {
ContentValues contentValues = new ContentValues();
contentValues.put(Data.MIMETYPE, mimeType);
contentValues.put(Data.DATA1, value);
contentValues.put(Data.IS_SUPER_PRIMARY, preferredValue ? 1 : 0);
if (type != null) {
contentValues.put(Data.DATA2, typeConstant);
// If a custom type, add a label
if (typeConstant == BaseTypes.TYPE_CUSTOM) {
contentValues.put(Data.DATA3, type);
}
}
return contentValues;
}
示例9: addContact
import android.provider.ContactsContract.Data; //导入依赖的package包/类
/**
* Synchronously insert a contact with the designated @name into
* the ContactsContentProvider. This code is explained at
* http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html.
*/
private void addContact(String name,
List<ContentProviderOperation> cpops) {
final int position = cpops.size();
// First part of operation.
cpops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE,
mOps.getAccountType())
.withValue(RawContacts.ACCOUNT_NAME,
mOps.getAccountName())
.withValue(Contacts.STARRED,
1)
.build());
// Second part of operation.
cpops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID,
position)
.withValue(Data.MIMETYPE,
StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME,
name)
.build());
}
示例10: lookupProfile
import android.provider.ContactsContract.Data; //导入依赖的package包/类
/**
* Returns the Data id for a sample SyncAdapter contact's profile row, or 0
* if the sample SyncAdapter user isn't found.
*
* @param resolver a content resolver
* @param userId the sample SyncAdapter user ID to lookup
* @return the profile Data row id, or 0 if not found
*/
private static long lookupProfile(ContentResolver resolver, String userId) {
long profileId = 0;
final Cursor c =
resolver.query(Data.CONTENT_URI, ProfileQuery.PROJECTION, ProfileQuery.SELECTION,
new String[]{String.valueOf(userId)}, null);
try {
if ((c != null) && c.moveToFirst()) {
profileId = c.getLong(ProfileQuery.COLUMN_ID);
}
} finally {
if (c != null) {
c.close();
}
}
return profileId;
}
示例11: getPhoneNumbers
import android.provider.ContactsContract.Data; //导入依赖的package包/类
public void getPhoneNumbers(String id)
{
Log.d("getPhoneNumbers", "looking data for contact id: " + id);
Cursor pCur = mContext.getContentResolver().query(Data.CONTENT_URI, new String[]
{ Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL }, Data.CONTACT_ID + "=?" + " AND "
+ Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", new String[]
{ String.valueOf(id) }, null);
while (pCur.moveToNext())
{
String phoneNumber = pCur.getString(1);
String phoneType = pCur.getString(2);
String phoneLabel = pCur.getString(3);
if (isNumeric(phoneType))
{
Log.d("getPhoneNumbers", "phoneNumber: " + phoneNumber + ", phoneType: " + phoneType + ", phoneLabel: " + phoneLabel);
}
}
pCur.close();
return;
}
示例12: addContactData
import android.provider.ContactsContract.Data; //导入依赖的package包/类
private void addContactData(String username, String phone, List<ContentProviderOperation> operations, int index) {
ContentProviderOperation.Builder builder;
final int opIndex = index * 3;
// create a Data record of common type 'StructuredName' for our RawContact
builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, opIndex)
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, username);
operations.add(builder.build());
// create a Data record of custom type 'org.kontalk.user' to display a link to the conversation
builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, opIndex)
.withValue(ContactsContract.Data.MIMETYPE, Users.CONTENT_ITEM_TYPE)
.withValue(DATA_COLUMN_DISPLAY_NAME, username)
.withValue(DATA_COLUMN_ACCOUNT_NAME, mContext.getString(R.string.app_name))
.withValue(DATA_COLUMN_PHONE, phone)
.withYieldAllowed(true);
operations.add(builder.build());
}
示例13: addEmail
import android.provider.ContactsContract.Data; //导入依赖的package包/类
public static void addEmail(Context c, long rawContactId, String email){
DeviceUtil.log(c, "adding email", email);
String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId
+ "' AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE+ "'";
Cursor cursor = c.getContentResolver().query(ContactsContract.Data.CONTENT_URI, new String[] { RawContacts.CONTACT_ID}, where, null, null);
if (cursor.getCount() == 0){
ContentValues contentValues = new ContentValues();
//op.put(ContactsContract.CommonDataKinds.StructuredPostal.CONTACT_ID, );
contentValues.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId);
contentValues.put(ContactsContract.CommonDataKinds.Email.ADDRESS, email);
c.getContentResolver().insert(ContactsContract.Data.CONTENT_URI, contentValues);
}
cursor.close();
}
示例14: populateStructuredName
import android.provider.ContactsContract.Data; //导入依赖的package包/类
private void populateStructuredName(Contact c) throws RemoteException {
@Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] {
/* 0 */ StructuredName.DISPLAY_NAME, StructuredName.PREFIX, StructuredName.GIVEN_NAME,
/* 3 */ StructuredName.MIDDLE_NAME, StructuredName.FAMILY_NAME, StructuredName.SUFFIX,
/* 6 */ StructuredName.PHONETIC_GIVEN_NAME, StructuredName.PHONETIC_MIDDLE_NAME, StructuredName.PHONETIC_FAMILY_NAME
}, StructuredName.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), StructuredName.CONTENT_ITEM_TYPE }, null);
if (cursor != null && cursor.moveToNext()) {
c.setDisplayName(cursor.getString(0));
c.setPrefix(cursor.getString(1));
c.setGivenName(cursor.getString(2));
c.setMiddleName(cursor.getString(3));
c.setFamilyName(cursor.getString(4));
c.setSuffix(cursor.getString(5));
c.setPhoneticGivenName(cursor.getString(6));
c.setPhoneticMiddleName(cursor.getString(7));
c.setPhoneticFamilyName(cursor.getString(8));
}
}
示例15: populateEmailAddresses
import android.provider.ContactsContract.Data; //导入依赖的package包/类
protected void populateEmailAddresses(Contact c) throws RemoteException {
@Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] { Email.TYPE, Email.ADDRESS, Email.LABEL, Email.IS_SUPER_PRIMARY },
Email.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), Email.CONTENT_ITEM_TYPE }, null);
while (cursor != null && cursor.moveToNext()) {
ezvcard.property.Email email = new ezvcard.property.Email(cursor.getString(1));
switch (cursor.getInt(0)) {
case Email.TYPE_HOME:
email.addType(EmailType.HOME);
break;
case Email.TYPE_WORK:
email.addType(EmailType.WORK);
break;
case Email.TYPE_MOBILE:
email.addType(Contact.EMAIL_TYPE_MOBILE);
break;
case Email.TYPE_CUSTOM:
String customType = cursor.getString(2);
if (!StringUtils.isEmpty(customType))
email.addType(EmailType.get(labelToXName(customType)));
}
if (cursor.getInt(3) != 0) // IS_PRIMARY
email.addType(EmailType.PREF);
c.getEmails().add(email);
}
}