Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
richterdennis opened this issue Oct 13, 2023 · 2 comments
Labels
good first issue Good for newcomers

Comments

@richterdennis
Copy link

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);
@tafelnl tafelnl added the good first issue Good for newcomers label Oct 21, 2023
@josuelmm
Copy link

Any update?

@josuelmm
Copy link

josuelmm commented Sep 13, 2024

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

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants