本文整理汇总了Java中android.provider.ContactsContract.PhoneLookup._ID属性的典型用法代码示例。如果您正苦于以下问题:Java PhoneLookup._ID属性的具体用法?Java PhoneLookup._ID怎么用?Java PhoneLookup._ID使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.provider.ContactsContract.PhoneLookup
的用法示例。
在下文中一共展示了PhoneLookup._ID属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContactsWithPush
public Collection<ContactData> getContactsWithPush(Context context) {
final ContentResolver resolver = context.getContentResolver();
final String[] inProjection = new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};
List<String> pushNumbers = TextSecureDirectory.getInstance(context).getActiveNumbers();
final Collection<ContactData> lookupData = new ArrayList<>(pushNumbers.size());
for (String pushNumber : pushNumbers) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber));
Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
try {
if (lookupCursor != null && lookupCursor.moveToFirst()) {
final ContactData contactData = new ContactData(lookupCursor.getLong(0), lookupCursor.getString(1));
contactData.numbers.add(new NumberData("XecureChat", pushNumber));
lookupData.add(contactData);
}
} finally {
if (lookupCursor != null)
lookupCursor.close();
}
}
return lookupData;
}
示例2: isSystemContact
public boolean isSystemContact(Context context, String number) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] projection = new String[]{PhoneLookup.DISPLAY_NAME, PhoneLookup.LOOKUP_KEY,
PhoneLookup._ID, PhoneLookup.NUMBER};
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
return true;
}
} finally {
if (cursor != null) cursor.close();
}
return false;
}
示例3: getContactUriForNumber
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;
}
示例4: getSelfIdentityUri
@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;
}
示例5: getContactsWithPush
public Collection<ContactData> getContactsWithPush(Context context) {
final ContentResolver resolver = context.getContentResolver();
final String[] inProjection = new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};
List<String> pushNumbers = TextSecureDirectory.getInstance(context).getActiveNumbers();
final Collection<ContactData> lookupData = new ArrayList<>(pushNumbers.size());
for (String pushNumber : pushNumbers) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber));
Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
try {
if (lookupCursor != null && lookupCursor.moveToFirst()) {
final ContactData contactData = new ContactData(lookupCursor.getLong(0), lookupCursor.getString(1));
contactData.numbers.add(new NumberData("TextSecure", pushNumber));
lookupData.add(contactData);
}
} finally {
if (lookupCursor != null)
lookupCursor.close();
}
}
return lookupData;
}
示例6: getContactsWithPush
public Collection<ContactData> getContactsWithPush(Context context) {
final ContentResolver resolver = context.getContentResolver();
final String[] inProjection = new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};
List<String> pushNumbers = TextSecureDirectory.getInstance(context).getActiveNumbers();
final Collection<ContactData> lookupData = new ArrayList<ContactData>(pushNumbers.size());
for (String pushNumber : pushNumbers) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber));
Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
try {
if (lookupCursor != null && lookupCursor.moveToFirst()) {
final ContactData contactData = new ContactData(lookupCursor.getLong(0), lookupCursor.getString(1));
contactData.numbers.add(new NumberData("TextSecure", pushNumber));
lookupData.add(contactData);
}
} finally {
if (lookupCursor != null)
lookupCursor.close();
}
}
return lookupData;
}
示例7: getContactsWithPush
public Collection<ContactData> getContactsWithPush(Context context) {
final ContentResolver resolver = context.getContentResolver();
final String[] inProjection = new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};
List<String> pushNumbers = Directory.getInstance(context).getActiveNumbers();
final Collection<ContactData> lookupData = new ArrayList<ContactData>(pushNumbers.size());
for (String pushNumber : pushNumbers) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber));
Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
try {
if (lookupCursor != null && lookupCursor.moveToFirst()) {
final ContactData contactData = new ContactData(lookupCursor.getLong(0), lookupCursor.getString(1));
contactData.numbers.add(new NumberData("TextSecure", pushNumber));
lookupData.add(contactData);
}
} finally {
if (lookupCursor != null)
lookupCursor.close();
}
}
return lookupData;
}
示例8: contactExists
public boolean contactExists(Context context, String number) {
// / number is the phone number
Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(number));
String[] mPhoneNumberProjection = { PhoneLookup._ID,
PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
Cursor cur = context.getContentResolver().query(lookupUri,
mPhoneNumberProjection, null, null, null);
try {
if (cur.moveToFirst()) {
return true;
}
} finally {
if (cur != null)
cur.close();
}
return false;
}
示例9: getId
/**
* Returns the ID of the number passed as a parameter.
*
* @param contactNumber
* The number whose ID is to be returned.
* @return String The ID of the contact. Returns null if contact is not
* saved in the phone.
*/
public String getId(String contactNumber) {
String contactId = null;
ContentResolver contentResolver = context.getContentResolver();
Uri uri = Uri.withAppendedPath(
ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(contactNumber));
String[] projection = new String[] {
ContactsContract.Contacts.DISPLAY_NAME, PhoneLookup._ID };
Cursor cursor = contentResolver
.query(uri, projection, null, null, null);
if (cursor != null) {
while (cursor.moveToNext()) {
contactId = cursor.getString(cursor
.getColumnIndexOrThrow(PhoneLookup._ID));
break;
}
cursor.close();
}
return contactId;
}
示例10: getContactFromPhoneNumber
public static Contact getContactFromPhoneNumber(String phoneNumber, Context context) {
Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
final String[] contactProjection = new String[] {PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};
Cursor c = context.getContentResolver().query(contactUri, contactProjection, null, null, null);
Contact contact = new Contact(phoneNumber, phoneNumber);
try {
if (c.moveToFirst()) {
long id = c.getLong(c.getColumnIndex(PhoneLookup._ID));
String name = c.getString(c.getColumnIndex(PhoneLookup.DISPLAY_NAME));
contact = new Contact(id, phoneNumber, name);
}
} catch (Exception e) {
Log.d(TAG, "Unable to retrieve contact with phone number " + phoneNumber);
} finally {
c.close();
}
return contact;
}
示例11: searchContactForPhone
/**
* <a href="http://developer.android.com/reference/android/provider/ContactsContract.PhoneLookup.html"> PhoneLookup</a>
*
* @param context
* @param phoneNumber
* @return
*/
public static ContactVo searchContactForPhone(Context context, String phoneNumber) {
String contactName = null;
long contactId = -1l;
if (isPermissionReadContact(context)) {
Log.d(TAG, String.format("Search Contact Name for Phone [%s]", phoneNumber));
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
final String[] selection = new String[]{ PhoneLookup._ID, PhoneLookup.LOOKUP_KEY, PhoneLookup.DISPLAY_NAME};
Cursor cur = context.getContentResolver().query(uri, selection, null, null, null);
try {
if (cur != null && cur.moveToFirst()) {
contactId = cur.getLong(cur.getColumnIndexOrThrow(PhoneLookup._ID));
contactName = cur.getString(cur.getColumnIndex(PhoneLookup.DISPLAY_NAME));
}
} finally {
cur.close();
}
}
Log.d(TAG, String.format("Found Contact %s Name for Phone [%s] : %s", contactId, phoneNumber, contactName));
ContactVo result = null;
if (contactId != -1l) {
result = new ContactVo(contactId, contactName);
}
return result;
}
示例12: isPrioritySender
private static boolean isPrioritySender(int prioritySenders, String number) {
if (prioritySenders == Policy.PRIORITY_SENDERS_ANY) {
return true;
} else {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] projection = new String[]{PhoneLookup._ID, PhoneLookup.STARRED};
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
boolean exists = false;
int starred = 0;
try {
if (cursor != null && cursor.moveToFirst()) {
exists = true;
starred = cursor.getInt(cursor.getColumnIndexOrThrow(PhoneLookup.STARRED));
}
} finally {
if (cursor != null) {
cursor.close();
}
}
if (prioritySenders == Policy.PRIORITY_SENDERS_CONTACTS && exists) {
return true;
} else if (prioritySenders == Policy.PRIORITY_SENDERS_STARRED && starred == 1) {
return true;
}
return false;
}
}
示例13: getUidForSms
private static long getUidForSms(Context context, String number) {
long uid = -1;
long contactId = -1;
ContentResolver contentResolver = context.getContentResolver();
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] projection = new String[] { PhoneLookup._ID };
Cursor cursor = contentResolver.query(uri, projection, null, null, null);
if (cursor != null) {
while (cursor.moveToNext()) {
contactId = cursor.getLong(cursor.getColumnIndexOrThrow(PhoneLookup._ID));
}
cursor.close();
}
// second query
if (contactId != -1) {
String[] contactProjection = new String[] {
ContactsContract.Data.RAW_CONTACT_ID
};
Cursor contactCursor = contentResolver.query(ContactsContract.Data.CONTENT_URI,
contactProjection,
ContactsContract.Data.CONTACT_ID + " = ? ",
new String[] { contactId + "" },
null);
if (contactCursor != null) {
while (contactCursor.moveToNext()) {
uid = contactCursor.getLong(contactCursor.getColumnIndexOrThrow(ContactsContract.Data.RAW_CONTACT_ID));
break;
}
contactCursor.close();
}
}
return uid;
}
示例14: get
public ArrayList<Contact> get() {
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] projection = new String[] {
PhoneLookup._ID,
PhoneLookup.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.CommonDataKinds.Phone.LABEL,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
String[] simTypesQueryParts = new String[simTypes.length];
Arrays.fill(simTypesQueryParts, ContactsContract.RawContacts.ACCOUNT_TYPE + " <> ?");
String simTypesQuery = TextUtils.join(" AND ", simTypesQueryParts);
String selection = ContactsContract.RawContacts.ACCOUNT_TYPE + " IS NULL OR (" + simTypesQuery + ")";
String[] selectionArgs = simTypes;
Cursor results = resolver.query(
uri,
projection,
selection,
selectionArgs,
null
);
// create array of Phone contacts and fill it
final ArrayList<Contact> phoneContacts = new ArrayList<>();
int indexId = results.getColumnIndex(PhoneLookup._ID);
int indexName = results.getColumnIndex(PhoneLookup.DISPLAY_NAME);
int indexType = results.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE);
int indexLabel = results.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL);
int indexNumber = results.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
while (results.moveToNext()) {
int type = results.getInt(indexType);
String custom = results.getString(indexLabel);
final Contact phoneContact = new Contact(
results.getString(indexId),
results.getString(indexName),
results.getString(indexNumber),
(String) Phone.getTypeLabel(this.activity.getResources(), type, custom)
);
phoneContacts.add(phoneContact);
}
results.close();
return phoneContacts;
}
示例15: retrieveContactUri
public Uri retrieveContactUri(Contact contact) {
String lookupKey;
Long contactId;
Cursor result = null;
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] projection = new String[] { ContactsContract.Contacts.LOOKUP_KEY, ContactsContract.RawContacts.CONTACT_ID };
String selection;
String[] selectionArgs;
// at first try to resolve with contacts id
if (contact.getId() != null) {
selection = PhoneLookup._ID + "=?";
selectionArgs = new String[] { contact.getId() };
result = resolver.query(uri, projection, selection, selectionArgs, null);
// check if unique result
if (result.getCount() != 1) {
result.close();
result = null;
}
}
// if no contact id or no result, try alternate method
if (result == null) {
selection = ContactsContract.Contacts.DISPLAY_NAME + " = '?' AND "
+ ContactsContract.CommonDataKinds.Phone.NUMBER + " = '?'"
;
selectionArgs = new String[] { contact.getName(), contact.getNumber() };
result = resolver.query(uri, projection, selection, selectionArgs, null);
// check if unique result
if (result.getCount() != 1) {
result.close();
result = null;
}
}
// check for result
if (result == null) {
return null;
}
// get results
result.moveToNext();
lookupKey = result.getString(0);
contactId = result.getLong(1);
result.close();
// create contact URI
return ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
}