本文整理汇总了Java中android.provider.ContactsContract.CommonDataKinds.Phone.CONTACT_ID属性的典型用法代码示例。如果您正苦于以下问题:Java Phone.CONTACT_ID属性的具体用法?Java Phone.CONTACT_ID怎么用?Java Phone.CONTACT_ID使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.provider.ContactsContract.CommonDataKinds.Phone
的用法示例。
在下文中一共展示了Phone.CONTACT_ID属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadUserInfoFromPhone
private void loadUserInfoFromPhone(){
User user = AppManager.getSession();
if (user != null) {
etName.setText(user.getName());
Util.setProfileImage(user.getPhoto(), imgProfile);
} else {
if (checkPermissions()) {
String[] projection = new String[] {
Phone.DISPLAY_NAME,
Phone.HAS_PHONE_NUMBER,
Phone.NUMBER,
Phone.CONTACT_ID};
Cursor cursor = getApplication().getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
if (cursor.moveToFirst()){
etName.setText(cursor.getString(cursor.getColumnIndex("display_name")));
}
cursor.close();
}
}
}
示例2: loadContact2
public static List<ContactEntity> loadContact2(Context context){
List<ContactEntity> contacts=new ArrayList<ContactEntity>();
ContentResolver cr=context.getContentResolver();
String [] projection={Phone.DISPLAY_NAME,Phone.NUMBER,Photo.PHOTO_ID,Phone.CONTACT_ID};
Cursor c=cr.query(Phone.CONTENT_URI, projection, null, null, null);
if(c!=null){
while(c.moveToNext()){
String name=c.getString(0);
String number=c.getString(1);
long contactId=c.getLong(3);
long photoId=c.getLong(2);
Bitmap bitmap=null;
if(photoId>0){
Uri uri=ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
InputStream input=ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
bitmap=BitmapFactory.decodeStream(input);
}
ContactEntity entity=new ContactEntity();
entity.setName(name);
entity.setNumber(number);
entity.setBitmap(bitmap);
contacts.add(entity);
}
}
c.close();
return contacts;
}
示例3: onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (RESULT_OK == resultCode) {
String selection = Phone.CONTACT_ID + "=?";
Uri result = data.getData();
String id = result.getLastPathSegment();
String[] arguments = new String[]{id};
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query(Phone.CONTENT_URI, null, selection, arguments, null);
int index = cursor.getColumnIndex(Phone.DATA);
if (cursor.moveToFirst()) {
String phone = cursor.getString(index);
set(this, phone);
EditText edit = (EditText) findViewById(R.id.contact);
edit.setText(phone);
}
cursor.close();
}
}
示例4: matchContactNumbers
public void matchContactNumbers(Map<String, Contact> contactsMap) {
// Get numbers
final String[] numberProjection = new String[]{
Phone.NUMBER,
Phone.TYPE,
Phone.CONTACT_ID,
};
Cursor phone = new CursorLoader(context,
Phone.CONTENT_URI,
numberProjection,
null,
null,
null).loadInBackground();
if (phone.moveToFirst()) {
final int contactNumberColumnIndex = phone.getColumnIndex(Phone.NUMBER);
final int contactTypeColumnIndex = phone.getColumnIndex(Phone.TYPE);
final int contactIdColumnIndex = phone.getColumnIndex(Phone.CONTACT_ID);
while (!phone.isAfterLast()) {
final String number = phone.getString(contactNumberColumnIndex);
final String contactId = phone.getString(contactIdColumnIndex);
Contact contact = contactsMap.get(contactId);
if (contact == null) {
continue;
}
final int type = phone.getInt(contactTypeColumnIndex);
String customLabel = "Custom";
CharSequence phoneType = ContactsContract.CommonDataKinds.Phone.getTypeLabel(context.getResources(), type, customLabel);
contact.addNumber(number, phoneType.toString());
phone.moveToNext();
}
}
phone.close();
}
示例5: 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);
}
示例6: 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);
}
示例7: getNumbers
public List<String> getNumbers(Context context) {
List<String> phoneNumbers = new LinkedList<>();
Uri uri = Phone.CONTENT_URI;
String[] projection = new String[] {
Phone.NUMBER,
Phone.IS_PRIMARY
};
String clause = Phone.CONTACT_ID + " = ?";
String[] args = new String[] { getId() };
Cursor cursor = context.getContentResolver().query(uri, projection, clause, args, null);
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
do {
boolean isPrimary = cursor.getInt(cursor.getColumnIndex(Phone.IS_PRIMARY)) != 0;
String number = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
if (isPrimary) {
phoneNumbers.add(0, number);
} else {
phoneNumbers.add(number);
}
} while (cursor.moveToNext());
}
} finally {
cursor.close();
}
}
return phoneNumbers;
}
示例8: 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;
}
}
示例9: getLocalContactsInfos
public List<ContactsInfo> getLocalContactsInfos() {
ContentResolver cr = context.getContentResolver();
String str[] = {Phone.CONTACT_ID, Phone.DISPLAY_NAME, Phone.NUMBER,
Phone.PHOTO_ID};
Cursor cur = null;
try {
cur = cr.query(
Phone.CONTENT_URI, str, null,
null, null);
if (cur != null) {
while (cur.moveToNext()) {
contactsInfo = new ContactsInfo();
contactsInfo.setContactsPhone(cur.getString(cur.getColumnIndex(Phone.NUMBER)));// 得到手机号码
contactsInfo.setContactsName(cur.getString(cur.getColumnIndex(Phone.DISPLAY_NAME)));
// contactsInfo.setContactsPhotoId(cur.getLong(cur.getColumnIndex(Phone.PHOTO_ID)));
// long contactid = cur.getLong(cur.getColumnIndex(Phone.CONTACT_ID));
// long photoid = cur.getLong(cur.getColumnIndex(Phone.PHOTO_ID));
// // 如果photoid 大于0 表示联系人有头像 ,如果没有给此人设置头像则给他一个默认的
// if (photoid > 0) {
// Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactid);
// InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
// contactsInfo.setBitmap(BitmapFactory.decodeStream(input));
// } else {
// contactsInfo.setBitmap(BitmapFactory.decodeResource(context.getResources(),
// R.mipmap.ic_launcher));
// }
// Log.e("TAG", "--联系人电话--" + contactsInfo.getContactsPhone());
// System.out.println("--联系人电话--" + contactsInfo.getContactsPhone());
localList.add(contactsInfo);
}
cur.close();
}
} catch (SecurityException e) {
new AlertDialog.Builder(mContext).setMessage("你的手机未对行咖开启读取手机通讯录权限,快去手机应用管理里去设置吧!").setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent("com.android.settings.ManageApplications");
mContext.startActivity(intent);
mContext.finish();
}
}).create().show();
}
return localList;
}
示例10: getMobileNumber
public synchronized Future<String> getMobileNumber(final Context context) {
if (mNumber != null) {
return new Present<>(mNumber);
} else {
return new FutureImpl<String>() {
@Override
public String get() {
List<String> numbers = new LinkedList<>();
Uri uri = Phone.CONTENT_URI;
String[] projection = new String[] {
Phone.NUMBER,
Phone.IS_PRIMARY,
Phone.TYPE
};
String clause = Phone.CONTACT_ID + " = ? AND " + Phone.TYPE + " = ?";
String[] args = new String[] { getId(), Integer.toString(Phone.TYPE_MOBILE) };
Cursor cursor = context.getContentResolver().query(uri, projection, clause, args, null);
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
do {
boolean isPrimary = cursor.getInt(cursor.getColumnIndex(Phone.IS_PRIMARY)) != 0;
String number = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
if (isPrimary) {
numbers.add(0, number);
} else {
numbers.add(number);
}
} while (cursor.moveToNext());
}
} finally {
cursor.close();
}
}
if (numbers.isEmpty()) {
return null;
} else {
return setNumber(numbers.get(0));
}
}
};
}
}
示例11: 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;
}
}
示例12: getNumberfromContact
private String getNumberfromContact(String contact, Boolean debugging) {
ContentResolver cr = getContentResolver();
String result = null;
boolean valid = false;
String val_num = null;
int contact_id = 0;
// Cursor1 search for valid Database Entries who matches the contact name
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[]{ ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.HAS_PHONE_NUMBER };
String selection = ContactsContract.Contacts.DISPLAY_NAME + "=?";
String[] selectionArgs = new String[]{String.valueOf(contact)};
String sortOrder = null;
Cursor cursor1 = cr.query(uri, projection, selection, selectionArgs, sortOrder);
if(cursor1.moveToFirst()){
if(cursor1.getInt(cursor1.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)) == 1){
contact_id = cursor1.getInt(cursor1.getColumnIndex(ContactsContract.Contacts._ID));
if (debugging) {
Log.d(TAG, "C1 found Database ID: " + contact_id + " with Entry: " + cursor1.getString(cursor1.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
}
// Cursor 2 search for valid MOBILE Telephone numbers (selection = Phone.TYPE 2)
Uri uri2 = ContactsContract.Data.CONTENT_URI;
String[] projection2 = new String[]{ Phone.NUMBER, Phone.TYPE };
String selection2 = Phone.CONTACT_ID + "=? AND " + Data.MIMETYPE + "=? AND " + Phone.TYPE + "=2";
String[] selectionArgs2 = new String[]{ String.valueOf(contact_id), Phone.CONTENT_ITEM_TYPE };
String sortOrder2 = Data.IS_PRIMARY + " desc";
Cursor cursor2 = cr.query(uri2, projection2, selection2, selectionArgs2, sortOrder2);
if(cursor2.moveToFirst()){
result = cursor2.getString(cursor2.getColumnIndex(Phone.NUMBER));
if (debugging) {
Log.d(TAG, "C2 found number: " + result);
}
}
cursor2.close();
}
cursor1.close();
}
if (result != null) {
valid = isNumberValid(result);
}
if (!valid) {
if (debugging) {
Log.d(TAG, "number seems invalid, try to resolve: " + result);
}
val_num = makeNumberValid(result);
if (val_num != null) {
valid = true;
result = val_num;
if (debugging) {
Log.d(TAG, "return modified number: " + result);
}
}
}
if (valid) {
if (debugging) {
Log.d(TAG, "return number: " + result);
}
return result;
} else {
return null;
}
}