Was ich will, auf das Profil des Kontakts in der Kontaktanwendung gehen, wenn ich einen Artikel auf einer Liste drücken:Kontakt nicht auf Vorsatz Gefunden mit Kontakt Anwendung
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);
}
});
ich rufen Sie die Liste aller Kontakte (Name, Telefonnummer und ID) mit den getContacts() beim Start der Anwendung. Zumindest funktionieren die Namen und Telefonnummern.
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;
}
In der onLongPress Funktion, wenn ich Toast, erhalte ich URIs wie: "Inhalt: //com.android.contacts/contacts/780" und einen Toast (I Umsetzung nicht): „Kontakt nicht gefunden "
Ich weiß, wie man zur Kontaktanwendung (ich habe Code, der dafür funktioniert), aber ich kann nicht auf ein bestimmtes Kontaktprofil gehen.
Ich habe bereits viele Lösungen auf dem Internet einschließlich Stackoverflow, aber keine dieser Lösungen gearbeitet hat ...
Die ID, die Sie in der URI übergeben ist falsch, denke ich. Ich verwende ContactsContract.RawContacts.CONTACT_ID und es funktioniert absolut gut – Gautam