Java 类android.provider.ContactsContract.Contacts 实例源码
项目:Linphone4Android
文件:ApiElevenPlus.java
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;
}
项目:Linphone4Android
文件:ApiElevenPlus.java
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;
}
项目:TextSecure
文件:ContactAccessor.java
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;
}
项目:q-mail
文件:RecipientLoader.java
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);
}
项目: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;
}
项目:GitHub
文件:MainActivity.java
@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);
}
});
}
项目:GitHub
文件:MainActivity.java
@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);
}
项目:GitHub
文件:MainActivity.java
@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);
}
}
项目:GitHub
文件:MainActivity.java
@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);
}
项目:GitHub
文件:MainActivity.java
@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);
}
}
项目:PeSanKita-android
文件:ContactAccessor.java
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;
}
项目:PeSanKita-android
文件:ContactIdentityManagerGingerbread.java
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;
}
项目:PeSanKita-android
文件:ContactIdentityManagerGingerbread.java
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();
}
}
项目:PeSanKita-android
文件:ContactIdentityManagerICS.java
@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;
}
项目:CSipSimple
文件:ContactsUtils5.java
@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;
}
项目:CSipSimple
文件:ContactsUtils5.java
@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;
}
项目:CSipSimple
文件:ContactsUtils5.java
@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;
}
项目:CSipSimple
文件:ContactsUtils14.java
@Override
public Bitmap getContactPhoto(Context ctxt, Uri uri, boolean hiRes, Integer defaultResource) {
Bitmap img = null;
InputStream s = Contacts.openContactPhotoInputStream(
ctxt.getContentResolver(), uri, hiRes);
img = BitmapFactory.decodeStream(s);
if (img == null && defaultResource != null) {
BitmapDrawable drawableBitmap = ((BitmapDrawable) ctxt.getResources().getDrawable(
defaultResource));
if (drawableBitmap != null) {
img = drawableBitmap.getBitmap();
}
}
return img;
}
项目:Cable-Android
文件:ContactAccessor.java
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;
}
项目:Cable-Android
文件:ContactIdentityManagerGingerbread.java
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;
}
项目:Cable-Android
文件:ContactIdentityManagerGingerbread.java
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();
}
}
项目:Cable-Android
文件:ContactIdentityManagerICS.java
@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;
}
项目:AOSP-Kayboard-7.1.2
文件:ContactsManager.java
/**
* Returns the number of contacts in contacts content provider.
*/
public int getContactCount() {
// TODO: consider switching to a rawQuery("select count(*)...") on the database if
// performance is a bottleneck.
Cursor cursor = null;
try {
cursor = mContext.getContentResolver().query(Contacts.CONTENT_URI,
ContactsDictionaryConstants.PROJECTION_ID_ONLY, null, null, null);
if (null == cursor) {
return 0;
}
return cursor.getCount();
} catch (final SQLiteException e) {
Log.e(TAG, "SQLiteException in the remote Contacts process.", e);
} finally {
if (null != cursor) {
cursor.close();
}
}
return 0;
}
项目:AOSP-Kayboard-7.1.2
文件:ContactsBinaryDictionary.java
/**
* Loads data within content providers to the dictionary.
*/
private void loadDictionaryForUriLocked(final Uri uri) {
if (!PermissionsUtil.checkAllPermissionsGranted(
mContext, Manifest.permission.READ_CONTACTS)) {
Log.i(TAG, "No permission to read contacts. Not loading the Dictionary.");
}
final ArrayList<String> validNames = mContactsManager.getValidNames(uri);
for (final String name : validNames) {
addNameLocked(name);
}
if (uri.equals(Contacts.CONTENT_URI)) {
// Since we were able to add content successfully, update the local
// state of the manager.
mContactsManager.updateLocalState(validNames);
}
}
项目:AOSP-Kayboard-7.1.2
文件:ContactsContentObserver.java
public void registerObserver(final ContactsChangedListener listener) {
if (!PermissionsUtil.checkAllPermissionsGranted(
mContext, Manifest.permission.READ_CONTACTS)) {
Log.i(TAG, "No permission to read contacts. Not registering the observer.");
// do nothing if we do not have the permission to read contacts.
return;
}
if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "registerObserver()");
}
mContactsChangedListener = listener;
mContentObserver = new ContentObserver(null /* handler */) {
@Override
public void onChange(boolean self) {
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD)
.execute(ContactsContentObserver.this);
}
};
final ContentResolver contentResolver = mContext.getContentResolver();
contentResolver.registerContentObserver(Contacts.CONTENT_URI, true, mContentObserver);
}
项目:K9-MailClient
文件:RecipientLoader.java
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(getContext().getContentResolver(), lookupKeyUri);
if (contactContentUri == null) {
return;
}
String contactIdStr = getContactIdFromContactUri(contactContentUri);
Cursor cursor = getContext().getContentResolver().query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
PROJECTION, ContactsContract.CommonDataKinds.Email.CONTACT_ID + "=?",
new String[] { contactIdStr }, null);
if (cursor == null) {
return;
}
fillContactDataFromCursor(cursor, recipients, recipientMap);
}
项目:K9-MailClient
文件:RecipientLoader.java
private void fillContactDataFromQuery(String query, List<Recipient> recipients,
Map<String, 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, query };
Cursor cursor = contentResolver.query(queryUri, PROJECTION, selection, selectionArgs, SORT_ORDER);
if (cursor == null) {
return;
}
fillContactDataFromCursor(cursor, recipients, recipientMap);
if (observerContact != null) {
observerContact = new ForceLoadContentObserver();
contentResolver.registerContentObserver(queryUri, false, observerContact);
}
}
项目:messengerxmpp
文件:ContactDetailsActivity.java
@Override
public void onClick(View v) {
if (contact.getSystemAccount() == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(
ContactDetailsActivity.this);
builder.setTitle(getString(R.string.action_add_phone_book));
builder.setMessage(getString(R.string.add_phone_book_text,
contact.getJid()));
builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.add), addToPhonebook);
builder.create().show();
} else {
String[] systemAccount = contact.getSystemAccount().split("#");
long id = Long.parseLong(systemAccount[0]);
Uri uri = ContactsContract.Contacts.getLookupUri(id, systemAccount[1]);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
startActivity(intent);
}
}
项目:TextSecure
文件:ContactAccessor.java
private long getContactIdFromLookupUri(Context context, Uri uri) {
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri,
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();
}
}
项目:TextSecure
文件:ContactPhotoFactory.java
public static Bitmap getLocalUserContactPhoto(Context context, Uri uri) {
if (uri == null) return getDefaultContactPhoto(context);
Bitmap contactPhoto = localUserContactPhotoCache.get(uri);
if (contactPhoto == null) {
Cursor cursor = context.getContentResolver().query(uri, CONTENT_URI_PROJECTION,
null, null, null);
if (cursor != null && cursor.moveToFirst()) {
contactPhoto = getContactPhoto(context, Uri.withAppendedPath(Contacts.CONTENT_URI,
cursor.getLong(0) + ""));
} else {
contactPhoto = getDefaultContactPhoto(context);
}
localUserContactPhotoCache.put(uri, contactPhoto);
}
return contactPhoto;
}
项目:TextSecure
文件:ContactIdentityManagerGingerbread.java
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;
}
项目:TextSecure
文件:ContactIdentityManagerGingerbread.java
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();
}
}
项目:TextSecure
文件:ContactIdentityManagerICS.java
@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;
}
项目:TextSecure
文件:RecipientProvider.java
private RecipientDetails getRecipientDetails(Context context, String number) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
Cursor cursor = context.getContentResolver().query(uri, CALLER_ID_PROJECTION,
null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
Uri contactUri = Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1));
Bitmap contactPhoto = ContactPhotoFactory.getContactPhoto(context, Uri.withAppendedPath(Contacts.CONTENT_URI,
cursor.getLong(2)+""));
return new RecipientDetails(cursor.getString(0), cursor.getString(3), contactUri, contactPhoto,
BitmapUtil.getCircleCroppedBitmap(contactPhoto));
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
项目:android-giftwise
文件:MainActivity.java
private void asyncQueryDisplayName(final Uri lookupUri)
{
final String DISPLAY_NAME_COL = Build.VERSION.SDK_INT
>= Build.VERSION_CODES.HONEYCOMB ?
Contacts.DISPLAY_NAME_PRIMARY :
Contacts.DISPLAY_NAME;
final String[] projection = new String[] {
Contacts._ID,
DISPLAY_NAME_COL,
};
NotifyingAsyncQueryHandler asyncQuery = new NotifyingAsyncQueryHandler(this, this);
asyncQuery.startQuery(1, lookupUri,
lookupUri,
projection,
null,
null,
null);
}
项目:hancel_android
文件:BaseActivity.java
private Uri retrieveContactPhotoUri() {
Cursor cursorID = getContentResolver().query(uriContact, new String[]{Contacts._ID}, null, null, null);
String contactID = "";
if (cursorID != null && cursorID.moveToFirst()) {
contactID = cursorID.getString(cursorID.getColumnIndex(Contacts._ID));
cursorID.close();
}
//
//// return Uri.withAppendedPath(Contacts.CONTENT_URI,contactID);
// return ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, new Long(contactID));
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI,new Long(contactID));
Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
return photoUri;
}
项目:FMTech
文件:PeopleSearchActivity.java
public final void a(String paramString1, String paramString2, jjd paramjjd)
{
if (getIntent().getBooleanExtra("picker_mode", false))
{
Intent localIntent1 = new Intent();
localIntent1.putExtra("person_id", paramString1);
localIntent1.putExtra("person_data", paramjjd);
setResult(-1, localIntent1);
finish();
return;
}
if (paramString2 != null)
{
Intent localIntent2 = new Intent("android.intent.action.VIEW", Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, paramString2));
localIntent2.addFlags(524288);
startActivity(localIntent2);
return;
}
startActivity(efj.b(this, this.d.c(), paramString1, null, false));
}
项目:TextSecureSMP
文件:ContactAccessor.java
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;
}
项目:TextSecureSMP
文件:ContactAccessor.java
private long getContactIdFromLookupUri(Context context, Uri uri) {
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri,
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();
}
}