本文整理汇总了Java中android.provider.ContactsContract.CommonDataKinds.Phone类的典型用法代码示例。如果您正苦于以下问题:Java Phone类的具体用法?Java Phone怎么用?Java Phone使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Phone类属于android.provider.ContactsContract.CommonDataKinds包,在下文中一共展示了Phone类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContactData
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
private ContactData getContactData(Context context, String displayName, long id) {
ContactData contactData = new ContactData(id, displayName);
Cursor numberCursor = null;
try {
numberCursor = context.getContentResolver().query(Phone.CONTENT_URI, null,
Phone.CONTACT_ID + " = ?",
new String[] {contactData.id + ""}, null);
while (numberCursor != null && numberCursor.moveToNext()) {
int type = numberCursor.getInt(numberCursor.getColumnIndexOrThrow(Phone.TYPE));
String label = numberCursor.getString(numberCursor.getColumnIndexOrThrow(Phone.LABEL));
String number = numberCursor.getString(numberCursor.getColumnIndexOrThrow(Phone.NUMBER));
String typeLabel = Phone.getTypeLabel(context.getResources(), type, label).toString();
contactData.numbers.add(new NumberData(typeLabel, number));
}
} finally {
if (numberCursor != null)
numberCursor.close();
}
return contactData;
}
示例2: loadUserInfoFromPhone
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
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();
}
}
}
示例3: sendContactDetails
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
public static void sendContactDetails(Context context, String ph_no, ContactItemDataModel contactData, Uri uri) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
String phoneNo = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
String name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
if (phoneNo == null) phoneNo = "";
if (name == null) name = "";
JsonObject contact_message = new JsonObject();
contact_message.addProperty("name", name);
contact_message.addProperty("number", phoneNo);
SendMessageService.startSendTextMessage(context, ph_no,
contactData.getContact_id(),
contact_message.toString(),
"contact", contactData.is_bot(), Utils.getCurrentTimestamp());
}
}
示例4: onActivityResult
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
@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);
}
}
}
}
示例5: getNumbersForThreadSearchFilter
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
public List<String> getNumbersForThreadSearchFilter(String constraint, ContentResolver contentResolver) {
LinkedList<String> numberList = new LinkedList<String>();
Cursor cursor = null;
try {
cursor = contentResolver.query(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI,
Uri.encode(constraint)),
null, null, null, null);
while (cursor != null && cursor.moveToNext()) {
numberList.add(cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER)));
}
} finally {
if (cursor != null)
cursor.close();
}
return numberList;
}
示例6: getPhoneContacts
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
/**
* 得到手机通讯录联系人信息
*/
private void getPhoneContacts() {
ContentResolver resolver = mContext.getContentResolver();
//query查询,得到结果的游标
Cursor phoneCursor = resolver.query(Phone.CONTENT_URI, PHONES_PROJECTION, null, null, null);
if (phoneCursor != null) {
while (phoneCursor.moveToNext()) {
//得到手机号码
String phoneNumber = phoneCursor.getString(PHONES_NUMBER_INDEX);
//当手机号码为空的或者为空字段 跳过当前循环
if (TextUtils.isEmpty(phoneNumber)) {
continue;
}
//得到联系人名称
String contactName = phoneCursor.getString(PHONES_DISPLAY_NAME_INDEX);
ContactModel cb = new ContactModel();
cb.setContactName(contactName);
cb.setPhoneNumber(phoneNumber);
contactsList.add(cb);
}
phoneCursor.close();
}
}
示例7: getContactFromPhonebook
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
/**
* 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();
}
示例8: loadContact2
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
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;
}
示例9: getPhoneContacts
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
/**
* 得到手机通讯录联系人信息
*/
private void getPhoneContacts() {
//query查询,得到结果的游标
Cursor phoneCursor = mResolver.query(Phone.CONTENT_URI, PHONES_PROJECTION, null, null, null);
if (phoneCursor != null) {
while (phoneCursor.moveToNext()) {
//得到手机号码
String phoneNumber = phoneCursor.getString(PHONES_NUMBER_INDEX);
//当手机号码为空的或者为空字段 跳过当前循环
if (TextUtils.isEmpty(phoneNumber)) {
continue;
}
//得到联系人名称
String contactName = phoneCursor.getString(PHONES_DISPLAY_NAME_INDEX);
ContactModel cb = new ContactModel();
cb.setContactName(contactName);
cb.setPhoneNumber(phoneNumber);
contactsList.add(cb);
}
phoneCursor.close();
}
}
示例10: addContact
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
public static void addContact(String name, String number)
{
ContentValues values = new ContentValues();
//������RawContacts.CONTENT_URIִ��һ����ֵ���룬Ŀ���ǻ�ȡϵͳ���ص�rawContactId
Uri rawContactUri = m_context.getContentResolver().insert(RawContacts.CONTENT_URI, values);
long rawContactId = ContentUris.parseId(rawContactUri);
//��data�������������
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);//��������
values.put(StructuredName.GIVEN_NAME, name);
m_context.getContentResolver().insert(ContactsContract.Data.CONTENT_URI, values);
//��data�����绰����
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, number);
values.put(Phone.TYPE, Phone.TYPE_MOBILE);
m_context.getContentResolver().insert(ContactsContract.Data.CONTENT_URI, values);
}
示例11: changeContact
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
public static void changeContact(String name, String number, String ContactId)
{
Log.i("huahua", name);
ContentValues values = new ContentValues();
// ��������
values.put(StructuredName.GIVEN_NAME, name);
m_context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + "=?",
new String[] { ContactId,StructuredName.CONTENT_ITEM_TYPE });
//���µ绰
values.clear();
values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, number);
m_context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
values,
Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + "=?",
new String[] { ContactId,Phone.CONTENT_ITEM_TYPE});
}
示例12: testAppendNameProperties_phone
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
@Test
public void testAppendNameProperties_phone() {
final VCardBuilder builder = new VCardBuilder(VCardConfig.VCARD_TYPE_V30_GENERIC,
VCardConfig.DEFAULT_EXPORT_CHARSET);
final ContentValues cv = new ContentValues();
final List<ContentValues> group = new ArrayList<>();
cv.put(ContactsContract.Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
cv.put(Email.IS_PRIMARY, 0);
cv.put(Email.DATA1, "(123) 123-4567");
group.add(cv);
final String card = builder.appendPhones(group, null).toString();
assertEquals(PHONE_CARD, card);
}
示例13: doInBackground
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
@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;
}
示例14: getNumbersForThreadSearchFilter
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
public List<String> getNumbersForThreadSearchFilter(Context context, String constraint) {
LinkedList<String> numberList = new LinkedList<>();
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI,
Uri.encode(constraint)),
null, null, null, null);
while (cursor != null && cursor.moveToNext()) {
numberList.add(cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER)));
}
} finally {
if (cursor != null)
cursor.close();
}
return numberList;
}
示例15: onActivityResult
import android.provider.ContactsContract.CommonDataKinds.Phone; //导入依赖的package包/类
@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();
}
}