Open rohaitas opened 11 months ago
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); } }`
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());