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

WhatsApp format of vcard is not supported? #144

Open
rohaitas opened this issue Sep 21, 2023 · 0 comments
Open

WhatsApp format of vcard is not supported? #144

rohaitas opened this issue Sep 21, 2023 · 0 comments

Comments

@rohaitas
Copy link

rohaitas commented Sep 21, 2023

What am i missing? I am able to add contact as a file. But not in sender intent

` VCard vcard = new VCard();
String fileName = "null";
String num = getRawNUmber(item);
if (num != null) {
vcard.addTelephoneNumber(num, TelephoneType.CELL);
}
fileName = item.getDisplayNamePrimary();
vcard.setFormattedName(item.getDisplayNamePrimary());

    vcard.setKind(Kind.individual());
    vcard.setGender(Gender.male());
    vcard.addLanguage("en-US");

    StructuredName n = new StructuredName();
    n.setFamily("Doe");
    n.setGiven("Jonathan");
    n.getPrefixes().add("Mr");
    vcard.setStructuredName(n);

    vcard.setRevision(Revision.now());
    vcard.validate(VCardVersion.V4_0);

    File files = new File(context.getFilesDir(), fileName + ".vcf");

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {

        try {
            files.createNewFile();
            Path file = Paths.get(files.getAbsolutePath());
            Ezvcard.write(vcard).version(VCardVersion.V4_0).go(file);
            Uri fileUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", files);
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("text/vcard");
            shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Share Contact");
            shareIntent.putExtra(Intent.EXTRA_TEXT, "Here's a contact.");
            context.startActivity(Intent.createChooser(shareIntent, "Share contact using..."));

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants