android-contacts

Getting Contact ID from Android Contacts database is not working as intended

允我心安 提交于 2019-11-29 07:46:44
I have the following code. int phoneContactID = new Random().nextInt(); Cursor contactLookupCursor = context.getContentResolver().query( Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,Uri.encode(contactNumber)), new String[] {PhoneLookup.DISPLAY_NAME, PhoneLookup._ID},null,null,null); try { contactLookupCursor.moveToFirst(); while(contactLookupCursor.moveToNext()) { phoneContactID = contactLookupCursor.getInt(contactLookupCursor.getColumnIndexOrThrow(PhoneLookup._ID)); } } finally { contactLookupCursor.close(); } The problem in the above code is that even if I give a existing number in

Pick contact directly from contact picker intent

随声附和 提交于 2019-11-29 06:15:05
Hello I want to pick a contact from our default contact book intent. I tried several ways to do it. Please find the code below. The problem with all those code is that they open one intermediate documents screen with few options there user has to select contact and than it opens contact book. private void openContactIntent() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT, ContactsContract.Contacts.CONTENT_URI); intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); startActivityForResult(intent, REQ_CONTACT_DIRECTORY); } I also tried Intent intent = new Intent(Intent

How can I programmatically add a contact?

谁都会走 提交于 2019-11-29 04:52:25
I am trying to programmatically add a contact in Android. Here is my code: ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); int rawContactInsertIndex = ops.size(); ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI) .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE,"Google") .withValue(ContactsContract.RawContacts.ACCOUNT_NAME,"user1@gmail.com") .build()); ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) .withValueBackReference(Data.RAW_CONTACT_ID,rawContactInsertIndex) .withValue(ContactsContract.Data.MIMETYPE

Android: Contact Picker Intent | Cannot instantiate the type Uri

北战南征 提交于 2019-11-29 04:27:39
I am trying to pick contacts with phone number only.And I am following this code static final int PICK_CONTACT_REQUEST = 1; // The request code ... private void pickContact() { Intent pickContactIntent = new Intent(Intent.ACTION_PICK, new Uri("content://contacts")); pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST); } But unfortunately, its showing an error: Cannot instantiate the type Uri Actually I have another working code which is working perfectly, but crashes on selecting Email

Changing contact's image to a large photo via PHOTO_FILE_ID in Android

十年热恋 提交于 2019-11-29 03:59:57
This seems to work for small images: ContentValues values = new ContentValues(); values.put(ContactsContract.Data.RAW_CONTACT_ID, id); values.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1); values.put(ContactsContract.CommonDataKinds.Photo.PHOTO, photo); values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE); if (photoRow >= 0) { context.getContentResolver().update(ContactsContract.Data.CONTENT_URI, values, ContactsContract.Data._ID + " = " + photoRow, null); } else { context.getContentResolver().insert(ContactsContract.Data.CONTENT_URI, values); }

AutoComplete with name and number as in native sms app Android

那年仲夏 提交于 2019-11-29 02:34:54
I want to add an AutoCompleteTextView in my app and search contacts by name and number as done in the native SMS app with android. I have looked on the internet and tried quite a few things, but I want my application to display it exactly as the android SMS app. Here is the code I am trying that searches only by Display_Name . public class MakePayment extends Activity { private AutoCompleteTextView mAuto; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.makepayment); mAuto =

How to update existing contact?

元气小坏坏 提交于 2019-11-28 23:11:43
I have one existing contact, I need to add a work address to that existing contact. I am using the following code, but it's not working. String selectPhone = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE + "'" + " AND " + ContactsContract.CommonDataKinds.StructuredPostal.TYPE + "=?"; String[] phoneArgs = new String[] {String.valueOf(ContactId), String.valueOf( ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK)}; ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI) .withSelection(selectPhone, phoneArgs)

How to listen contact inserted/updated/deleted in address book

风格不统一 提交于 2019-11-28 21:23:19
There are lots of questions related to it but none of them help me to get the solution. I am trying to sync all contacts from device to remote server and able to do it easily but when there is a change in contact like update/delete/insert(new contact) unable to find the solution. Tried using ContentObserver but onChange() is getting called multiple times. It's difficult to find the contact changes data. public class ContactService extends Service { private int mContactCount; @Override public IBinder onBind(Intent arg0) { return null; } @Override public void onCreate() { super.onCreate();

Accessing Android Contact Group Names

丶灬走出姿态 提交于 2019-11-28 18:28:49
Can you please tell me how to fetch contact groups programmatically stored in our android phone? final String[] GROUP_PROJECTION = new String[] { ContactsContract.Groups._ID, ContactsContract.Groups.TITLE }; cursor = getContentResolver().query( ContactsContract.Groups.CONTENT_URI, GROUP_PROJECTION, null, null, ContactsContract.Groups.TITLE); GlobalConfig.groupList.clear(); Group g = new Group(); g.GroupIdList += "0"; g.setGroupTitle("ALL"); GlobalConfig.groupList.add(g); while (cursor.moveToNext()) { String id = cursor.getString(cursor .getColumnIndex(ContactsContract.Groups._ID)); String

Cannot retrieve email from Contacts

五迷三道 提交于 2019-11-28 14:33:10
I want to retrieve email,phone number and contact names from my phone-book and display them in list-view. The name and numbers are coming perfectly but the emails are not retrieving. Here is the relevant code: public void getAllContacts(ContentResolver cr) { String email=""; Cursor phones = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, Phone.DISPLAY_NAME + " ASC"); //email = new String[phones.getCount()]; while (phones.moveToNext()) { String id = phones.getString(phones.getColumnIndex(ContactsContract.Contacts._ID)); String name=phones.getString(phones