本文整理汇总了Java中android.provider.ContactsContract类的典型用法代码示例。如果您正苦于以下问题:Java ContactsContract类的具体用法?Java ContactsContract怎么用?Java ContactsContract使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContactsContract类属于android.provider包,在下文中一共展示了ContactsContract类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeContactUpdatesReceiver
import android.provider.ContactsContract; //导入依赖的package包/类
private void initializeContactUpdatesReceiver() {
observer = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.w(TAG, "Detected android contact data changed, refreshing cache");
RecipientFactory.clearCache(ConversationListActivity.this);
ConversationListActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
chatsFragment.getListAdapter().notifyDataSetChanged();
}
});
}
};
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI,
true, observer);
}
示例2: getSelfIdentityUri
import android.provider.ContactsContract; //导入依赖的package包/类
@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;
}
示例3: onCreateLoader
import android.provider.ContactsContract; //导入依赖的package包/类
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
String[] projectionFields = new String[]{
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.PHOTO_URI
};
CursorLoader cursorLoader = new CursorLoader(MainActivity.this,
ContactsContract.Contacts.CONTENT_URI,
projectionFields,
null,
null,
null);
return cursorLoader;
}
示例4: readContactDetails
import android.provider.ContactsContract; //导入依赖的package包/类
private void readContactDetails(Cursor cursor) {
if (cursor != null && cursor.moveToFirst()) {
cursor.moveToPrevious();
while (cursor.moveToNext()) {
String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.LOOKUP_KEY));
ContactImpl contact = mContactsByLookupKey.get(lookupKey);
if (contact != null) {
readContactDetails(cursor, contact);
}
}
}
sortAndPostCopy(mContacts);
joinContactsAndGroups(mContacts);
}
示例5: onCreateLoader
import android.provider.ContactsContract; //导入依赖的package包/类
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
return new CursorLoader(this,
// Retrieve data rows for the device user's 'profile' contact.
Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,
// Select only email addresses.
ContactsContract.Contacts.Data.MIMETYPE +
" = ?", new String[]{ContactsContract.CommonDataKinds.Email
.CONTENT_ITEM_TYPE},
// Show primary email addresses first. Note that there won't be
// a primary email address if the user hasn't specified one.
ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
}
示例6: getNameEmailDetails
import android.provider.ContactsContract; //导入依赖的package包/类
public static List<String> getNameEmailDetails(ContentResolver resolver) {
ArrayList<String> names = new ArrayList<>();
Cursor cur = resolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
Cursor cur1 =
resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
new String[] { id }, null);
getEmailFromCursor(names, cur1);
cur1.close();
}
}
return names;
}
示例7: setPersonInfo
import android.provider.ContactsContract; //导入依赖的package包/类
private void setPersonInfo(final @NonNull Recipient recipient) {
this.recipient = recipient;
this.recipient.addListener(this);
final Context context = getContext();
new AsyncTask<Void, Void, ContactPhoto>() {
@Override
protected ContactPhoto doInBackground(Void... params) {
DisplayMetrics metrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Uri contentUri = ContactsContract.Contacts.lookupContact(context.getContentResolver(),
recipient.getContactUri());
windowManager.getDefaultDisplay().getMetrics(metrics);
return ContactPhotoFactory.getContactPhoto(context, contentUri, null, metrics.widthPixels);
}
@Override
protected void onPostExecute(final ContactPhoto contactPhoto) {
WebRtcCallScreen.this.photo.setImageDrawable(contactPhoto.asCallCard(context));
}
}.execute();
this.name.setText(recipient.getName());
this.phoneNumber.setText(recipient.getNumber());
}
示例8: createContact
import android.provider.ContactsContract; //导入依赖的package包/类
/**
* Start the activity to add information to an existing contact or add a
* new one.
*
* @param email An {@link Address} instance containing the email address
* of the entity you want to add to the contacts. Optionally
* the instance also contains the (display) name of that
* entity.
*/
public void createContact(final Address email) {
final Uri contactUri = Uri.fromParts("mailto", email.getAddress(), null);
final Intent contactIntent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
contactIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
contactIntent.setData(contactUri);
// Pass along full E-mail string for possible create dialog
contactIntent.putExtra(ContactsContract.Intents.EXTRA_CREATE_DESCRIPTION,
email.toString());
// Only provide personal name hint if we have one
final String senderPersonal = email.getPersonal();
if (senderPersonal != null) {
contactIntent.putExtra(ContactsContract.Intents.Insert.NAME, senderPersonal);
}
mContext.startActivity(contactIntent);
}
示例9: startContactsActivityIntent
import android.provider.ContactsContract; //导入依赖的package包/类
/**
* Starts the contacts intent and requests permission to write to contacts if permission doesn't exist
*/
public void startContactsActivityIntent(){
String[] permissions = {"android.permission.WRITE_CONTACTS"};
Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION);
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_CONTACTS) != PackageManager
.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(this, permissions, CONTACTS_PERMISSION);
}
else {
if (intent.resolveActivity(getPackageManager()) != null) {
intent.putExtra(ContactsContract.Intents.Insert.NAME, name);
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, email);
intent.putExtra(ContactsContract.Intents.Insert.PHONE, phone);
startActivity(intent);
}
}
}
示例10: getInputStream
import android.provider.ContactsContract; //导入依赖的package包/类
private InputStream getInputStream(Request data) throws IOException {
ContentResolver contentResolver = context.getContentResolver();
Uri uri = data.uri;
switch (matcher.match(uri)) {
case ID_LOOKUP:
uri = ContactsContract.Contacts.lookupContact(contentResolver, uri);
if (uri == null) {
return null;
}
// Resolved the uri to a contact uri, intentionally fall through to process the resolved uri
case ID_CONTACT:
return openContactPhotoInputStream(contentResolver, uri, true);
case ID_THUMBNAIL:
case ID_DISPLAY_PHOTO:
return contentResolver.openInputStream(uri);
default:
throw new IllegalStateException("Invalid uri: " + uri);
}
}
示例11: onOptionsItemSelected
import android.provider.ContactsContract; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case android.R.id.home:
finish();
return true;
case R.id.action_invite_friends:
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
startActivityForResult(intent, Constants.REQUEST_PERMISSIONS_CONTACT);
return true;
case R.id.action_add_friends:
AddContactDialog addContactDialog = new AddContactDialog();
addContactDialog.setOnAdded(this);
addContactDialog.show(getSupportFragmentManager(), "AddContactDialog");
return true;
}
return super.onOptionsItemSelected(item);
}
示例12: getName
import android.provider.ContactsContract; //导入依赖的package包/类
@Override
public CName getName() {
CName cName = new CName();
String familyName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME));
String givenName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
String photoUri = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI));
cName.setFamilyName(familyName);
cName.setDisplayName(displayName);
cName.setGivenName(givenName);
cName.setPhotoUri(photoUri);
return cName;
}
示例13: getGroupsMap
import android.provider.ContactsContract; //导入依赖的package包/类
private SparseArray<Group> getGroupsMap() {
SparseArray<Group> idGroupMap = new SparseArray<>();
Cursor groupCursor = mResolver.query(
ContactsContract.Groups.CONTENT_URI,
new String[]{
ContactsContract.Groups._ID,
ContactsContract.Groups.TITLE
}, null, null, null
);
if (groupCursor != null) {
while (groupCursor.moveToNext()) {
int id = groupCursor.getInt(groupCursor.getColumnIndex(ContactsContract.Groups._ID));
String title = groupCursor.getString(groupCursor.getColumnIndex(ContactsContract.Groups.TITLE));
idGroupMap.put(id, new Group()
.setGroupId(id)
.setGroupTitle(title));
}
groupCursor.close();
}
return idGroupMap;
}
示例14: onLoadFinished
import android.provider.ContactsContract; //导入依赖的package包/类
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
contactsAdapter.clear();
Set<String> favoriteContacts = CustodeUtils.getFavoriteContacts(this);
LinkedList<ContactsAdapter.ContactItem> tempArray = new LinkedList<>();
int favoriteLimit = 0; // usato per ordinare i contatti preferiti in cima alla lista
int nameColumnIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
int numberColumnIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
while (cursor.moveToNext()) {
String name = cursor.getString(nameColumnIndex);
String number = cursor.getString(numberColumnIndex);
boolean favorite = favoriteContacts.remove(number);
if (favorite)
tempArray.add(favoriteLimit++, new ContactsAdapter.ContactItem(name, number, true));
else
tempArray.addLast(new ContactsAdapter.ContactItem(name, number, false));
}
if (favoriteContacts.size() > 0) // => favoriteContacts contiene numeri che non sono più presenti in rubrica
for (String favoriteContact : favoriteContacts)
tempArray.addFirst(new ContactsAdapter.ContactItem("", favoriteContact, true));
contactsAdapter.addAll(tempArray);
}
示例15: onBindItemViewHolder
import android.provider.ContactsContract; //导入依赖的package包/类
@Override
public void onBindItemViewHolder(ViewHolder viewHolder, @NonNull Cursor cursor) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ContactsDatabase.ID_COLUMN));
int contactType = cursor.getInt(cursor.getColumnIndexOrThrow(ContactsDatabase.CONTACT_TYPE_COLUMN));
String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN));
String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_COLUMN));
int numberType = cursor.getInt(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_TYPE_COLUMN));
String label = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.LABEL_COLUMN));
String labelText = ContactsContract.CommonDataKinds.Phone.getTypeLabel(getContext().getResources(),
numberType, label).toString();
int color = (contactType == ContactsDatabase.PUSH_TYPE) ? drawables.getColor(0, 0xa0000000) :
drawables.getColor(1, 0xff000000);
boolean preSelected = numbers != null && numbers.contains(number);
viewHolder.getView().unbind();
viewHolder.getView().set(id, contactType, name, number, labelText, color, multiSelect);
viewHolder.getView().setChecked(preSelected || selectedContacts.containsKey(id));
viewHolder.getView().setEnabled(!preSelected);
}