contacts icon indicating copy to clipboard operation
contacts copied to clipboard

How to open a contact with default contact app after creating a contact

Open richterdennis opened this issue 2 years ago • 2 comments

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);

richterdennis avatar Oct 13 '23 14:10 richterdennis

Any update?

josuelmm avatar Sep 13 '24 01:09 josuelmm

` @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);
    }
}

} `

josuelmm avatar Sep 13 '24 01:09 josuelmm