contacts
contacts copied to clipboard
How to open a contact with default contact app after creating a contact
I can successfully create a contact with
const { contactId } = await Contacts.createContact({ contact: contactData });
How do I open the contact with the default contact app?
After researching for hours, the best I achieved is
AppLauncher.openUrl({
url: 'com.google.android.contacts',
});
This opens the contact app on android but not the contact itself.
A dedicated function to open the new created contact would be nice. Something like this:
Contacts.openContact(contactId);
Any update?
` @PluginMethod public void openContact(PluginCall call) { if (!isContactsPermissionGranted()) { requestContactsPermission(call); } else { String contactId = call.getString("contactId");
if (contactId == null) {
call.reject("Parameter `contactId` not provided.");
return;
}
try {
// Crear un Intent para abrir el contacto con el contactId proporcionado
Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contactId);
Intent intent = new Intent(Intent.ACTION_VIEW, contactUri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Asegurarse de que la actividad se inicie en un nuevo task
getContext().startActivity(intent);
call.resolve();
} catch (Exception e) {
call.reject("Failed to open contact with id: " + contactId, e);
}
}
} `