本文整理汇总了Java中android.provider.ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME属性的典型用法代码示例。如果您正苦于以下问题:Java Phone.DISPLAY_NAME属性的具体用法?Java Phone.DISPLAY_NAME怎么用?Java Phone.DISPLAY_NAME使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.provider.ContactsContract.CommonDataKinds.Phone
的用法示例。
在下文中一共展示了Phone.DISPLAY_NAME属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == REQUEST_CONTACTS) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
String[] projection = { Phone.DISPLAY_NAME };
try (Cursor cursor = getContentResolver().query(uri, projection,
null, null, null)) {
if (cursor == null || cursor.getCount() <= 0) {
Log.e(TAG, "Null cursor found. Weird! Probably no contact was picked");
return;
}
cursor.moveToFirst();
int nameColumnIndex = cursor.getColumnIndex(Phone.DISPLAY_NAME);
String name = cursor.getString(nameColumnIndex);
nameField.setText(name);
}
}
}
}
示例3: getContactFromPhonebook
/**
* Helper to retrieve a contact's information from the phone book activity
*
* @param data The Intent carrying the data of the phone book selection
* @param context Context to get content resolver from
* @return Contact object storing the name and phone number of the retrieved contact
*/
public static ContactUtils.Contact getContactFromPhonebook(Intent data, Context context) {
// Get the data from the Intent
Uri contact_data = data.getData();
// Query the Intent's data and extract the ID and name of the contact
String[] projection = {Phone.DISPLAY_NAME, Phone.NUMBER};
String sel = String.format("%s = %s", Phone.TYPE, Phone.TYPE_MOBILE);
Cursor c = context.getContentResolver().query(contact_data, projection, sel, null, null);
if (c.moveToFirst()) {
if (c.moveToFirst()) {
String name = c.getString(c.getColumnIndex(Phone.DISPLAY_NAME));
String phone = convertToE164(c.getString(c.getColumnIndex(Phone.NUMBER)));
return new ContactUtils.Contact(name, phone);
}
c.close();
}
return new ContactUtils.Contact();
}
示例4: 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;
}
示例5: doInBackground
@Override
protected Void doInBackground(Long... ids) {
String[] projection = new String[] {Phone.DISPLAY_NAME, Phone.TYPE, Phone.NUMBER, Phone.LABEL};
long contactId = ids[0];
final Cursor phoneCursor = getActivity().getContentResolver().query(
Phone.CONTENT_URI,
projection,
Data.CONTACT_ID + "=?",
new String[]{String.valueOf(contactId)},
null);
if(phoneCursor != null && phoneCursor.moveToFirst() && phoneCursor.getCount() == 1) {
final int contactNumberColumnIndex = phoneCursor.getColumnIndex(Phone.NUMBER);
mPhoneNumber = phoneCursor.getString(contactNumberColumnIndex);
int type = phoneCursor.getInt(phoneCursor.getColumnIndexOrThrow(Phone.TYPE));
mPhoneLabel = phoneCursor.getString(phoneCursor.getColumnIndex(Phone.LABEL));
mPhoneLabel = Phone.getTypeLabel(getResources(), type, mPhoneLabel).toString();
phoneCursor.close();
}
return null;
}
示例6: onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_7);
mPhone = (TextView) findViewById(R.id.phone);
getListView().setOnItemSelectedListener(this);
// Get a cursor with all numbers.
// This query will only return contacts with phone numbers
Cursor c = getContentResolver().query(Phone.CONTENT_URI,
PHONE_PROJECTION, Phone.NUMBER + " NOT NULL", null, null);
startManagingCursor(c);
ListAdapter adapter = new SimpleCursorAdapter(this,
// Use a template that displays a text view
android.R.layout.simple_list_item_1,
// Give the cursor to the list adapter
c,
// Map the DISPLAY_NAME column to...
new String[] {Phone.DISPLAY_NAME},
// The "text1" view defined in the XML template
new int[] {android.R.id.text1});
setListAdapter(adapter);
}
示例7: getUserName
private String getUserName(String number) {
String[] projection = new String[] { Phone.NUMBER, Phone.DISPLAY_NAME };
Uri uri = Uri.withAppendedPath(
ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI,
number);
ContentResolver cr = getContentResolver();
Cursor phone = cr.query(uri, projection, null, null, null);
String userName = "";
if (phone.moveToFirst()) {
userName = phone
.getString(phone
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
Log.d(SMSLOGACTIVITY, number + " " + userName);
}
phone.close();
return userName;
}
示例8: fetchAll
public ArrayList<Contact> fetchAll() {
String[] projectionFields = new String[]{
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
};
ArrayList<Contact> listContacts = new ArrayList<>();
CursorLoader cursorLoader = new CursorLoader(context,
ContactsContract.Contacts.CONTENT_URI,
projectionFields, // the columns to retrieve
null, // the selection criteria (none)
null, // the selection args (none)
Phone.DISPLAY_NAME + " ASC" // the sort order (default), use null for default
);
Cursor c = cursorLoader.loadInBackground();
final Map<String, Contact> contactsMap = new HashMap<>(c.getCount());
if (c.moveToFirst()) {
int idIndex = c.getColumnIndex(ContactsContract.Contacts._ID);
int nameIndex = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
do {
String contactId = c.getString(idIndex);
String contactDisplayName = c.getString(nameIndex);
Contact contact = new Contact(contactId, contactDisplayName);
contactsMap.put(contactId, contact);
listContacts.add(contact);
} while (c.moveToNext());
}
c.close();
matchContactNumbers(contactsMap);
matchContactEmails(contactsMap);
return listContacts;
}
示例9: 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);
}
示例10: 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);
}
示例11: queryContact
private void queryContact() {
if (mHashMap != null) {
return ;
}
mHashMap = new HashMap<String, String>();
String[] PHONES_PROJECTION = new String[] {Phone.DISPLAY_NAME, Phone.NUMBER };
Cursor c = null;
try {
c = mContext.getContentResolver().query(Phone.CONTENT_URI, PHONES_PROJECTION,
null, null, null);
if (c != null) {
if (c.moveToFirst()) {
do {
String phoneNumber = c.getString(c.getColumnIndex(Phone.NUMBER));
String displayName = c.getString(c.getColumnIndex(Phone.DISPLAY_NAME));
if (phoneNumber.startsWith("+86")) {
phoneNumber = phoneNumber.substring("+86".length());
}
phoneNumber = phoneNumber.replaceAll("-", "");
phoneNumber = phoneNumber.replaceAll("\\s+", "");
//Log.d(Log.TAG, phoneNumber + " : " + displayName);
if (!TextUtils.isEmpty(displayName)) {
mHashMap.put(phoneNumber, displayName);
}
} while (c.moveToNext());
}
}
} catch(Exception e) {
e.printStackTrace();
} finally {
if (c != null) {
c.close();
}
}
}
示例12: 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;
}
}
示例13: 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);
}
}
示例14: 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;
}
示例15: onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_OK)
return;
switch (requestCode) {
case CONTACT_PICKER_RESULT:
if (data == null)
return;
Uri uri = data.getData();
String id = uri.getLastPathSegment();
Log.i(TAG, uri + "");
String[] projection = {
Phone.DISPLAY_NAME,
Phone.NUMBER
};
Cursor cursor = getContentResolver().query(Phone.CONTENT_URI,
projection,
Phone.CONTACT_ID + " = ? ",
new String[] {
id,
}, null);
if (cursor.moveToFirst()) {
displayName = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
phoneNumber = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
contactTextView.setText(displayName + "/" + phoneNumber);
setTriggerData();
}
break;
case CONNECT_RESULT:
/*
* Only ACTION_CONNECT needs the confirmation from
* onActivityResult(), listView.setOnItemClickListener handles
* all the other adding and removing of panic receivers.
*/
if (TextUtils.equals(requestAction, Panic.ACTION_CONNECT)) {
PanicTrigger.removeConnectedResponder(this, requestPackageName);
}
break;
}
}