コード例 #1
0
 private Uri lookupContact(String phone) {
   Cursor c = null;
   try {
     Uri phoneUri =
         Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone));
     String[] projection =
         new String[] {ContactsContract.Contacts._ID, ContactsContract.Contacts.LOOKUP_KEY};
     c = mContext.getContentResolver().query(phoneUri, projection, null, null, null);
     if (c != null && c.getCount() > 0) {
       c.moveToFirst();
       int lookupIdx = c.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY);
       int idIdx = c.getColumnIndex(ContactsContract.Contacts._ID);
       String lookupKey = c.getString(lookupIdx);
       long contactId = c.getLong(idIdx);
       return ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
     }
   } catch (Throwable t) {
     Log.w(TAG, "Problem getting content resolver or performing contacts query.", t);
   } finally {
     if (c != null) {
       c.close();
     }
   }
   return null;
 }
コード例 #2
0
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		super.onClick(v);
		
		switch(v.getId()) {
		case R.id.bt_contact:
			Uri uri = ContactsContract.Contacts.getLookupUri(((ViewHolder)findViewHolder(v))
					.contact.getContactId(), (((ViewHolder)findViewHolder(v)).contact.getLookUpKey()));
		    QuickContact.showQuickContact(this, v, uri, QuickContact.MODE_LARGE, null);
			break;
		}
		
		
	}
コード例 #3
0
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    // Get the Cursor
    Cursor cursor = ((SimpleCursorAdapter) parent.getAdapter()).getCursor();
    // Move to the selected contact
    cursor.moveToPosition(position);
    // Get the _ID value
    mContactId = cursor.getLong(CONTACT_ID_INDEX);
    // Get the selected LOOKUP KEY
    mContactKey = cursor.getString(LOOKUP_KEY_INDEX);
    // Create the contact's content Uri
    mContactUri = ContactsContract.Contacts.getLookupUri(mContactId, mContactKey);
    /*
     * You can use mContactUri as the content URI for retrieving
     * the details for a contact.
     */
    if (ACTION.equals(SHOW_CONTACT_ACTION)) {
      Intent openContact = new Intent(Intent.ACTION_VIEW, mContactUri);
      startActivity(openContact);
    } else {

    }
  }