当我按下列表中的项目时,我想要转到Contact
应用程序中联系人的个人资料:
viewHolder.swipeLayout.setOnLongClickListener(new SwipeLayout.LongClickListener() {
public void onLongPress(View view) {
Intent goContactIntent = new Intent(Intent.ACTION_VIEW);
String contactID = mData.get(position).getId();
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contactID);
Toast.makeText(mContext,"uri : "+uri, Toast.LENGTH_LONG).show();
goContactIntent.setData(uri);
view.getContext().startActivity(goContactIntent);
}
});
我在应用程序启动时使用getContacts()
检索所有联系人列表(姓名,电话号码和ID)。至少姓名和电话号码有效。
public ArrayList<Contact> getContacts() {
//Adress of the table in the database
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
//Retrieve data
String[] projection = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID};
//Initialize the cursor
Cursor people = getContentResolver().query(uri, projection, null, null, null);
int indexName = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
int indexNumber = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
int indexId = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID);
ArrayList<Contact> contacts = new ArrayList<Contact>();
//Shaping data
people.moveToFirst();
do {
String name = people.getString(indexName);
String number = people.getString(indexNumber);
String contactid = people.getString(indexId);
Contact contact1 = new Contact();
contact1.setFirstName(name);
contact1.setPhoneNumber(number);
contact1.setId(contactid);
contacts.add(contact1);
} while (people.moveToNext());
return contacts;
}
在onLongPress
函数中,当我敬酒时,我得到的URI类似于:&#34; content://com.android.contacts/contacts/780"
和敬酒(我没有实施):&#34;未找到联系人&#34;
我知道如何转到Contact
应用程序(我的代码适用于此),但我无法使用特定的联系人资料。
答案 0 :(得分:0)
我认为您在URI中传递的ID是错误的。我正在使用ContactsContract.RawContacts.CONTACT_ID
,它的工作非常好