联系人应用程序未按意图找到联系人
Contact Not Found on Intent with Contact Application
我想要的是当我按下列表中的项目时转到 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()
检索所有联系人的列表(姓名、phone 号码和 ID)。至少名字和 phone 数字有效。
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:"content://com.android.contacts/contacts/780"
祝酒词(我没有实现):"Contact not found"
我知道如何访问 Contact
应用程序(我有适用的代码),但我无法访问特定的联系人资料。
我认为你在 URI 中传递的 ID 是错误的。我正在使用 ContactsContract.RawContacts.CONTACT_ID
,它工作得很好
我想要的是当我按下列表中的项目时转到 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()
检索所有联系人的列表(姓名、phone 号码和 ID)。至少名字和 phone 数字有效。
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:"content://com.android.contacts/contacts/780"
祝酒词(我没有实现):"Contact not found"
我知道如何访问 Contact
应用程序(我有适用的代码),但我无法访问特定的联系人资料。
我认为你在 URI 中传递的 ID 是错误的。我正在使用 ContactsContract.RawContacts.CONTACT_ID
,它工作得很好