本文整理汇总了Java中android.provider.ContactsContract.CommonDataKinds.Phone._ID属性的典型用法代码示例。如果您正苦于以下问题:Java Phone._ID属性的具体用法?Java Phone._ID怎么用?Java Phone._ID使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.provider.ContactsContract.CommonDataKinds.Phone
的用法示例。
在下文中一共展示了Phone._ID属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateLoader
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
String[] columns = {Phone._ID, Phone.DISPLAY_NAME_PRIMARY, Phone.DATA};
String selection = Data.MIMETYPE + " = '" + Phone.CONTENT_ITEM_TYPE + "'";
String orderBy = Phone.DISPLAY_NAME_PRIMARY + " ASC";
return new CursorLoader(this, Phone.CONTENT_URI, columns, selection, null, orderBy);
}
示例2: onActivityCreated
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
long personId = getArguments().getLong(ContactsPickerActivity.SELECTED_CONTACT_ID);// getIntent().getLongExtra("id", 0);
Activity activity = getActivity();
Uri phonesUri = Phone.CONTENT_URI;
String[] projection = new String[] {
Phone._ID, Phone.DISPLAY_NAME,
Phone.TYPE, Phone.NUMBER, Phone.LABEL };
String selection = Phone.CONTACT_ID + " = ?";
String[] selectionArgs = new String[] { Long.toString(personId) };
mCursor = activity.getContentResolver().query(phonesUri,
projection, selection, selectionArgs, null);
mDisplayName = (TextView) activity.findViewById(R.id.display_name);
if (mCursor.moveToFirst()){
mDisplayName.setText(mCursor.getString(mCursor.getColumnIndex(Phone.DISPLAY_NAME)));
}
ListAdapter adapter = new PhoneNumbersAdapter(this.getActivity(),
R.layout.list_item_phone_number, mCursor,
new String[] {Phone.TYPE, Phone.NUMBER },
new int[] { R.id.label, R.id.phone_number });
setListAdapter(adapter);
}
示例3: runQueryOnBackgroundThread
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
String constraintPath = null;
if (constraint != null) {
constraintPath = constraint.toString();
}
Uri queryURI = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI,
Uri.encode(constraintPath));
String[] projection = { Phone._ID, Phone.CONTACT_ID, Phone.DISPLAY_NAME,
Phone.NUMBER, Phone.TYPE, Phone.LABEL, };
// default: all numbers
String selection = null;
String[] selectionArgs = null;
String filter = preferences.getString("filter_receiver", "");
if (filter.contains("M")) { // mobiles only
selection = Phone.TYPE + "=? OR " + Phone.TYPE + "=?";
selectionArgs = new String[] {
String.valueOf(Phone.TYPE_MOBILE),
String.valueOf(Phone.TYPE_WORK_MOBILE)};
}
if (filter.contains("H")) { // no home numbers
selection = Phone.TYPE + "<>?";
selectionArgs = new String[] { String.valueOf(Phone.TYPE_HOME) };
}
String sortOrder = Contacts.TIMES_CONTACTED + " DESC";
return context.getContentResolver()
.query(queryURI, projection, selection, selectionArgs, sortOrder);
}
示例4: getCursorForRecipientFilter
/***
* If the code below looks shitty to you, that's because it was taken
* directly from the Android source, where shitty code is all you get.
*/
public Cursor getCursorForRecipientFilter(CharSequence constraint,
ContentResolver mContentResolver)
{
final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," +
Contacts.DISPLAY_NAME + "," +
Contacts.Data.IS_SUPER_PRIMARY + " DESC," +
Phone.TYPE;
final String[] PROJECTION_PHONE = {
Phone._ID, // 0
Phone.CONTACT_ID, // 1
Phone.TYPE, // 2
Phone.NUMBER, // 3
Phone.LABEL, // 4
Phone.DISPLAY_NAME, // 5
};
String phone = "";
String cons = null;
if (constraint != null) {
cons = constraint.toString();
if (RecipientsAdapter.usefulAsDigits(cons)) {
phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons);
if (phone.equals(cons) && !PhoneNumberUtils.isWellFormedSmsAddress(phone)) {
phone = "";
} else {
phone = phone.trim();
}
}
}
Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons));
String selection = String.format("%s=%s OR %s=%s OR %s=%s",
Phone.TYPE,
Phone.TYPE_MOBILE,
Phone.TYPE,
Phone.TYPE_WORK_MOBILE,
Phone.TYPE,
Phone.TYPE_MMS);
Cursor phoneCursor = mContentResolver.query(uri,
PROJECTION_PHONE,
null,
null,
SORT_ORDER);
if (phone.length() > 0) {
ArrayList result = new ArrayList();
result.add(Integer.valueOf(-1)); // ID
result.add(Long.valueOf(-1)); // CONTACT_ID
result.add(Integer.valueOf(Phone.TYPE_CUSTOM)); // TYPE
result.add(phone); // NUMBER
/*
* The "\u00A0" keeps Phone.getDisplayLabel() from deciding
* to display the default label ("Home") next to the transformation
* of the letters into numbers.
*/
result.add("\u00A0"); // LABEL
result.add(cons); // NAME
ArrayList<ArrayList> wrap = new ArrayList<ArrayList>();
wrap.add(result);
ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap);
return new MergeCursor(new Cursor[] { translated, phoneCursor });
} else {
return phoneCursor;
}
}
示例5: loadPhoneContacts
/**
* load all contacts from Phone Contact
* this method needs async task because it may take too longer to load
* @param listener : success result handler
*/
public void loadPhoneContacts(ResultListener listener){
long startnow = android.os.SystemClock.uptimeMillis();
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] projection = new String[] {
Phone._ID,
Phone.DISPLAY_NAME,
Phone.NUMBER
};
Cursor people = context.getContentResolver().query(uri, projection, null, null, null);
int indexId = people.getColumnIndex(Phone._ID);
int indexName = people.getColumnIndex(Phone.DISPLAY_NAME);
int indexNumber = people.getColumnIndex(Phone.NUMBER);
RealmList<RealmContact> realmContacts = new RealmList<>();
if(people.moveToFirst()) {
do {
String idx = people.getString(indexId);
String name = people.getString(indexName);
String number = people.getString(indexNumber);
// Do work...
String phone = number.replace(" ", "").replace("-", "");
RealmContact contact = new RealmContact();
contact.setIdx(idx);
contact.setName(name);
contact.setPhone(phone);
/*boolean isExist = false;
for (int i = 0; i < phoneContacts.size(); i++){
RealmContact existContact = phoneContacts.get(i);
if (existContact.getIdx().equals(contact.getIdx())){
isExist = true;
break;
}
}
if (!isExist){
phoneContacts.add(contact);
}*/
realmContacts.add(contact);
} while (people.moveToNext());
saveContacts(realmContacts);
}
if (phoneContacts.isEmpty())
phoneContacts = getContacts(context);
long endnow = android.os.SystemClock.uptimeMillis();
long processingDuration = endnow - startnow;
Log.d("AppManager", "TimeForContacts " + (endnow - startnow) + " ms");
// analysis
Bundle params = new Bundle();
params.putLong("duration", processingDuration);
References.getInstance().analytics.logEvent("load_contacts", params);
if (listener != null) {
listener.onResult(true);
}
}
示例6: getContactInfoForPhoneUris
/**
* Get CacheEntry list for given phone URIs. This method will do single one query to
* get expected contacts from provider. Be sure passed in URIs are not null and contains
* only valid URIs.
*/
public List<Contact> getContactInfoForPhoneUris(Parcelable[] uris) {
if (uris.length == 0) {
return null;
}
StringBuilder idSetBuilder = new StringBuilder();
boolean first = true;
for (Parcelable p : uris) {
Uri uri = (Uri) p;
if ("content".equals(uri.getScheme())) {
if (first) {
first = false;
idSetBuilder.append(uri.getLastPathSegment());
} else {
idSetBuilder.append(',').append(uri.getLastPathSegment());
}
}
}
// Check whether there is content URI.
if (first) return null;
Cursor cursor = null;
if (idSetBuilder.length() > 0) {
final String whereClause = Phone._ID + " IN (" + idSetBuilder.toString() + ")";
cursor = mContext.getContentResolver().query(
PHONES_WITH_PRESENCE_URI, CALLER_ID_PROJECTION, whereClause, null, null);
}
if (cursor == null) {
return null;
}
List<Contact> entries = new ArrayList<>();
try {
while (cursor.moveToNext()) {
Contact entry = new Contact(cursor.getString(PHONE_NUMBER_COLUMN),
cursor.getString(CONTACT_NAME_COLUMN));
fillPhoneTypeContact(entry, cursor);
ArrayList<Contact> value = new ArrayList<>();
value.add(entry);
// Put the result in the cache.
mContactsHash.put(key(entry.mNumber, sStaticKeyBuffer), value);
entries.add(entry);
}
} finally {
cursor.close();
}
return entries;
}
示例7: getCursorForRecipientFilter
/***
* If the code below looks shitty to you, that's because it was taken
* directly from the Android source, where shitty code is all you get.
*/
public Cursor getCursorForRecipientFilter(CharSequence constraint,
ContentResolver mContentResolver)
{
final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," +
Contacts.DISPLAY_NAME + "," +
Contacts.Data.IS_SUPER_PRIMARY + " DESC," +
Phone.TYPE;
final String[] PROJECTION_PHONE = {
Phone._ID, // 0
Phone.CONTACT_ID, // 1
Phone.TYPE, // 2
Phone.NUMBER, // 3
Phone.LABEL, // 4
Phone.DISPLAY_NAME, // 5
};
String phone = "";
String cons = null;
if (constraint != null) {
cons = constraint.toString();
if (RecipientsAdapter.usefulAsDigits(cons)) {
phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons);
if (phone.equals(cons) && !PhoneNumberUtils.isWellFormedSmsAddress(phone)) {
phone = "";
} else {
phone = phone.trim();
}
}
}
Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons));
String selection = String.format("%s=%s OR %s=%s OR %s=%s",
Phone.TYPE,
Phone.TYPE_MOBILE,
Phone.TYPE,
Phone.TYPE_WORK_MOBILE,
Phone.TYPE,
Phone.TYPE_MMS);
Cursor phoneCursor = mContentResolver.query(uri,
PROJECTION_PHONE,
null,
null,
SORT_ORDER);
if (phone.length() > 0) {
ArrayList result = new ArrayList();
result.add(Integer.valueOf(-1)); // ID
result.add(Long.valueOf(-1)); // CONTACT_ID
result.add(Integer.valueOf(Phone.TYPE_CUSTOM)); // TYPE
result.add(phone); // NUMBER
/*
* The "\u00A0" keeps Phone.getDisplayLabel() from deciding
* to display the default label ("Home") next to the transformation
* of the letters into numbers.
*/
result.add("\u00A0"); // LABEL
result.add(cons); // NAME
ArrayList<ArrayList> wrap = new ArrayList<ArrayList>();
wrap.add(result);
ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap);
return new MergeCursor(new Cursor[] { translated, phoneCursor });
} else {
return phoneCursor;
}
}
示例8: getContactInfoForPhoneUris
/**
* Get CacheEntry list for given phone URIs. This method will do single one query to
* get expected contacts from provider. Be sure passed in URIs are not null and contains
* only valid URIs.
*/
public List<Contact> getContactInfoForPhoneUris(Parcelable[] uris) {
if (uris.length == 0) {
return null;
}
StringBuilder idSetBuilder = new StringBuilder();
boolean first = true;
for (Parcelable p : uris) {
Uri uri = (Uri) p;
if ("content".equals(uri.getScheme())) {
if (first) {
first = false;
idSetBuilder.append(uri.getLastPathSegment());
} else {
idSetBuilder.append(',').append(uri.getLastPathSegment());
}
}
}
// Check whether there is content URI.
if (first) return null;
Cursor cursor = null;
if (idSetBuilder.length() > 0) {
final String whereClause = Phone._ID + " IN (" + idSetBuilder.toString() + ")";
cursor = mContext.getContentResolver().query(
PHONES_WITH_PRESENCE_URI, CALLER_ID_PROJECTION, whereClause, null, null);
}
if (cursor == null) {
return null;
}
List<Contact> entries = new ArrayList<Contact>();
try {
while (cursor.moveToNext()) {
Contact entry = new Contact(cursor.getString(PHONE_NUMBER_COLUMN),
cursor.getString(CONTACT_NAME_COLUMN));
fillPhoneTypeContact(entry, cursor);
ArrayList<Contact> value = new ArrayList<Contact>();
value.add(entry);
// Put the result in the cache.
mContactsHash.put(key(entry.mNumber, sStaticKeyBuffer), value);
entries.add(entry);
}
} finally {
cursor.close();
}
return entries;
}