I want to use nfc_manager package in flutter in the app I am getting contact in VCARD type from an api according to login user. what I want to achieve is when two phones near each other I want the contact to be added in the other phone contacts list how to do that? I know I have to write nfc VACRD like this:
String vCardText = """
BEGIN:VCARD\r\n
VERSION:3.0\r\n
REV:2023-08-22T13:21:45Z\r\n
TEL;TYPE=WORK:1234567890\r\n
LABEL;CHARSET=UTF-8:mobile_number\r\n
END:VCARD\r\n
""";
Future<void> startNFC() async {
NfcManager.instance.startSession(
onDiscovered: (NfcTag tag) async {
await tag.writeNdef(
NdefMessage.fromRecords([NdefRecord.createMime('text/vcard', vCardText)]),
);
await NfcManager.instance.stopSession();
},
);
and to read :
String receivedVCardText = "No vCard received yet";
Future<void> startNFC() async {
NfcManager.instance.startSession(
onDiscovered: (NfcTag tag) async {
NdefMessage? message = await tag.readNdef();
if (message != null && message.records.isNotEmpty) {
NdefRecord record = message.records[0];
if (record.isMime && record.mimeType == 'text/vcard') {
String vCardText = record.text!;
setState(() {
receivedVCardText = vCardText;
});
}
}
await NfcManager.instance.stopSession();
},
);
}
so every time the user login I should write and then read, but how the contact will be added to the another phone contacts list. I mean when I read a vcard contact this contact can be added directly to phone contacts list ?
and how to make the read always works ? assume user didn't make a logout and still in app how to make read always work so whenever user turn nfc on it should read the contact?