简体   繁体   English

如何将电子邮件数据写入 NFC 标签?

[英]How do I write email data to an NFC tags?

I tried the following code for writing text data, and it's a work fine我尝试了以下代码来编写文本数据,效果很好

NdefRecord mimeRecord = NdefRecord.createMime("text/plain", remainingString.getBytes(Charset.forName("US-ASCII")));
ndef.writeNdefMessage(new NdefMessage(mimeRecord));

This for launch application.这用于启动应用程序。

NdefRecord[] records = {NdefRecord.createApplicationRecord("com.demo.abc"),

but i dont understand how to write email content.但我不明白如何编写电子邮件内容。

you could write two records , the first one is uri_record and second one is text_record你可以写两条记录,第一条是uri_record ,第二条是text_record

you could write in the first one the email address and in second one the text.你可以在第一个写电子邮件地址,在第二个写文本。

NdefRecord uri_record = NdefRecord.createUri("https://abc.defg.hi");
String text = "Here is the email content";

NdefRecord text_record= NdefRecord.createMime("text/plain", text.getBytes(Charset.forName("US-ASCII")));
NdefRecord[] records = {uri_record , text_record};
NdefMessage message = new NdefMessage(records);
ndef.connect();
ndef.writeNdefMessage(message);
ndef.close();

for write email data用于写入电子邮件数据

NdefRecord mimeRecord = NdefRecord.createUri("mailto:" + "abc@gmail.com" + "?body=" + "your email message");
ndef.writeNdefMessage(new NdefMessage(mimeRecord));

Understand carefully仔细了解

NdefRecord.createUri("mailto:" + "abc@gmail.com") 

write if you want to write only receiver email id into NFC tag如果您只想将接收者电子邮件 ID 写入 NFC 标签,请写入

NdefRecord.createUri("mailto:" + "abc@gmail.com" + "?body=" + "your email message")

write if you want to write receiver email id and message into NFC tag如果要将接收者电子邮件 ID 和消息写入 NFC 标签,请写入

NdefRecord mimeRecord = NdefRecord.createUri("mailto:" + "abc@gmail.com" + "?subject=" + "your email subject" + "&body=" + "your email message")

write if you want to write receiver email id, email subject and message into NFC tag如果要将接收者电子邮件 ID、电子邮件主题和消息写入 NFC 标签,请写入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM