本文整理汇总了Java中android.provider.ContactsContract.Contacts类的典型用法代码示例。如果您正苦于以下问题:Java Contacts类的具体用法?Java Contacts怎么用?Java Contacts使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Contacts类属于android.provider.ContactsContract包,在下文中一共展示了Contacts类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareAddContactIntent
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
public static Intent prepareAddContactIntent(String displayName, String sipUri) {
Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
intent.putExtra(Insert.NAME, displayName);
if (sipUri != null && sipUri.startsWith("sip:")) {
sipUri = sipUri.substring(4);
}
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
ContentValues sipAddressRow = new ContentValues();
sipAddressRow.put(Contacts.Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE);
sipAddressRow.put(SipAddress.SIP_ADDRESS, sipUri);
data.add(sipAddressRow);
intent.putParcelableArrayListExtra(Insert.DATA, data);
return intent;
}
示例2: prepareEditContactIntentWithSipAddress
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
public static Intent prepareEditContactIntentWithSipAddress(int id, String sipUri) {
Intent intent = new Intent(Intent.ACTION_EDIT, Contacts.CONTENT_URI);
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
intent.setData(contactUri);
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
ContentValues sipAddressRow = new ContentValues();
sipAddressRow.put(Contacts.Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE);
sipAddressRow.put(SipAddress.SIP_ADDRESS, sipUri);
data.add(sipAddressRow);
intent.putParcelableArrayListExtra(Insert.DATA, data);
return intent;
}
示例3: getNameFromContact
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
public String getNameFromContact(Context context, Uri uri) {
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, new String[] {Contacts.DISPLAY_NAME},
null, null, null);
if (cursor != null && cursor.moveToFirst())
return cursor.getString(0);
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
示例4: fillContactDataFromLookupKey
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
private void fillContactDataFromLookupKey(Uri lookupKeyUri, List<Recipient> recipients,
Map<String, Recipient> recipientMap) {
// We could use the contact id from the URI directly, but getting it from the lookup key is safer
Uri contactContentUri = Contacts.lookupContact(contentResolver, lookupKeyUri);
if (contactContentUri == null) {
return;
}
String contactIdStr = getContactIdFromContactUri(contactContentUri);
Cursor cursor = contentResolver.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
PROJECTION, ContactsContract.CommonDataKinds.Email.CONTACT_ID + "=?",
new String[] { contactIdStr }, null);
if (cursor == null) {
return;
}
fillContactDataFromCursor(cursor, recipients, recipientMap);
}
示例5: fillContactDataFromNameAndEmail
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
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;
}
示例6: onCreate
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageViewContact = (ImageView) findViewById(R.id.image_contact);
imageViewLookup = (ImageView) findViewById(R.id.image_lookup);
imageViewPhoto = (ImageView) findViewById(R.id.image_photo);
imageViewDisplayPhoto = (ImageView) findViewById(R.id.image_display_photo);
findViewById(R.id.button_pick_contact).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(intent, REQUEST_CONTACT);
}
});
}
示例7: onActivityResult
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CONTACT && resultCode == RESULT_OK) {
final Cursor cursor = getContentResolver().query(data.getData(), null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
final long contactId = cursor.getLong(cursor.getColumnIndex(Contacts._ID));
showContact(contactId);
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
示例8: showContact
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
@TargetApi(VERSION_CODES.ICE_CREAM_SANDWICH)
private void showContact(long id) {
GlideRequests glideRequests = GlideApp.with(this);
RequestOptions originalSize = new RequestOptions().override(Target.SIZE_ORIGINAL);
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
glideRequests.load(contactUri).apply(originalSize).into(imageViewContact);
Uri lookupUri = Contacts.getLookupUri(getContentResolver(), contactUri);
glideRequests.load(lookupUri).apply(originalSize).into(imageViewLookup);
Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
glideRequests.load(photoUri).apply(originalSize).into(imageViewPhoto);
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO);
glideRequests.load(displayPhotoUri).apply(originalSize).into(imageViewDisplayPhoto);
}
}
示例9: onActivityResult
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CONTACT && resultCode == RESULT_OK) {
Uri uri = Preconditions.checkNotNull(data.getData());
final Cursor cursor = getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
final long contactId = cursor.getLong(cursor.getColumnIndex(Contacts._ID));
showContact(contactId);
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
示例10: getContactUriForNumber
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
private Uri getContactUriForNumber(String number) {
String[] PROJECTION = new String[] {
PhoneLookup.DISPLAY_NAME,
PhoneLookup.LOOKUP_KEY,
PhoneLookup._ID,
};
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, PROJECTION, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
return Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1));
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
示例11: getSelfIdentityContactId
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
private long getSelfIdentityContactId() {
Uri contactUri = getSelfIdentityUri();
if (contactUri == null)
return -1;
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(contactUri,
new String[] {ContactsContract.Contacts._ID},
null, null, null);
if (cursor != null && cursor.moveToFirst()) {
return cursor.getLong(0);
} else {
return -1;
}
} finally {
if (cursor != null)
cursor.close();
}
}
示例12: getSelfIdentityUri
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
@SuppressLint("NewApi")
@Override
public Uri getSelfIdentityUri() {
String[] PROJECTION = new String[] {
PhoneLookup.DISPLAY_NAME,
PhoneLookup.LOOKUP_KEY,
PhoneLookup._ID,
};
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(ContactsContract.Profile.CONTENT_URI,
PROJECTION, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
return Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1));
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
示例13: getCSipPhonesByGroup
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
@Override
public List<String> getCSipPhonesByGroup(Context ctxt, String groupName) {
Cursor contacts = getContactsByGroup(ctxt, groupName);
ArrayList<String> results = new ArrayList<String>();
if (contacts != null) {
try {
while (contacts.moveToNext()) {
List<String> res = getCSipPhonesContact(ctxt, contacts.getLong(contacts
.getColumnIndex(Contacts._ID)));
results.addAll(res);
}
} catch (Exception e) {
Log.e(THIS_FILE, "Error while looping on contacts", e);
} finally {
contacts.close();
}
}
return results;
}
示例14: getContactInfo
import android.provider.ContactsContract.Contacts; //导入依赖的package包/类
@Override
public ContactInfo getContactInfo(Context context, Cursor cursor) {
ContactInfo ci = new ContactInfo();
// Get values
ci.displayName = cursor.getString(cursor.getColumnIndex(Contacts.DISPLAY_NAME));
ci.contactId = cursor.getLong(cursor.getColumnIndex(Contacts._ID));
ci.callerInfo.contactContentUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, ci.contactId);
ci.callerInfo.photoId = cursor.getLong(cursor.getColumnIndex(Contacts.PHOTO_ID));
int photoUriColIndex = cursor.getColumnIndex(Contacts.PHOTO_ID);
ci.status = cursor.getString(cursor.getColumnIndex(Contacts.CONTACT_STATUS));
ci.presence = cursor.getInt(cursor.getColumnIndex(Contacts.CONTACT_PRESENCE));
if (photoUriColIndex >= 0) {
String photoUri = cursor.getString(photoUriColIndex);
if (!TextUtils.isEmpty(photoUri)) {
ci.callerInfo.photoUri = Uri.parse(photoUri);
}
}
ci.hasPresence = !TextUtils.isEmpty(ci.status);
return ci;
}
示例15: getAddContactIntent
import android.provider.ContactsContract.Contacts; //导入依赖的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;
}