Android 如何将联系人(vcard格式)写入NdefMessage?
我试图在NFC标签中写入NdefMessage,以便在用户手机点击标签时,有一张显示联系人信息的NFC名片 我想通过我的主应用程序传递联系信息。在EditText字段上,但我希望用户打开联系人(Android的默认应用程序) 我很难理解如何编写正确的有效负载格式 希望你能在这件事上帮我!,谢谢。发件人: mime媒体:Android 如何将联系人(vcard格式)写入NdefMessage?,android,nfc,Android,Nfc,我试图在NFC标签中写入NdefMessage,以便在用户手机点击标签时,有一张显示联系人信息的NFC名片 我想通过我的主应用程序传递联系信息。在EditText字段上,但我希望用户打开联系人(Android的默认应用程序) 我很难理解如何编写正确的有效负载格式 希望你能在这件事上帮我!,谢谢。发件人: mime媒体:text/vcard 格式: 您可以使用来编写联系人并查看其书写方式。 这两个应用程序在Google Play上都是免费的。我得到了这个工作的许可。这对于高级用户来说很简单,但我认
text/vcard
格式: 您可以使用来编写联系人并查看其书写方式。
这两个应用程序在Google Play上都是免费的。我得到了这个工作的许可。这对于高级用户来说很简单,但我认为像我这样的新手会很高兴找到这样的东西。下面的示例代码,请注意,由于Type2标记约束,我硬编码了一些数据
private NdefRecord createRecord(String text)
throws UnsupportedEncodingException {
//Intent intent = getIntent();
//EditText editTextWeb = (EditText)
EditText editText = (EditText) findViewById(R.id.editTextWeblinks);
String nameVcard = "BEGIN:VCARD" +"\n"+ "VERSION:2.1" +"\n" + "N:;" + editText.getText().toString() + "\n" +"ORG: PlanAyala"+"\n"+ "TEL;HOME:6302421" +"\n"+ "END:VCARD";
byte[] uriField = nameVcard.getBytes(Charset.forName("US-ASCII"));
byte[] payload = new byte[uriField.length + 1]; //add 1 for the URI Prefix
//payload[0] = 0x01; //prefixes http://www. to the URI
System.arraycopy(uriField, 0, payload, 1, uriField.length); //appends URI to payload
NdefRecord nfcRecord = new NdefRecord(
NdefRecord.TNF_MIME_MEDIA, "text/vcard".getBytes(), new byte[0], payload);
return nfcRecord;
}
也许你现在已经知道答案了。不过,我的答案是 使用下面的字符串 开始:VCARD 版本:3.0 FN:这里有你的名字 组织:工作地点 电邮:sample@gmail.com 药品不良反应:;;美国加利福尼亚州山景城 网址:www.google.com 电话:123456 完:VCARD
或者,您也可以尝试写。感谢您发布此示例。它是否像你想的那样工作?也就是说,你从你自己的应用程序发送联系人信息,它会在接收设备上打开Android的默认联系人应用程序?是的,我通过文本提供Vcard数据。当您将此MIME类型声明为text/vcard时,Android系统将打开一个支持此类信息的应用程序,在这种情况下,People应用程序将添加NFC标签上包含的联系信息,从而为您提供联系信息。我在ndef编写器应用程序上运行了这段代码。让我知道这是否对你有帮助:@maze\u mx你能用电子邮件格式更新答案吗?那对我会有帮助的
private NdefRecord createRecord(String text)
throws UnsupportedEncodingException {
//Intent intent = getIntent();
//EditText editTextWeb = (EditText)
EditText editText = (EditText) findViewById(R.id.editTextWeblinks);
String nameVcard = "BEGIN:VCARD" +"\n"+ "VERSION:2.1" +"\n" + "N:;" + editText.getText().toString() + "\n" +"ORG: PlanAyala"+"\n"+ "TEL;HOME:6302421" +"\n"+ "END:VCARD";
byte[] uriField = nameVcard.getBytes(Charset.forName("US-ASCII"));
byte[] payload = new byte[uriField.length + 1]; //add 1 for the URI Prefix
//payload[0] = 0x01; //prefixes http://www. to the URI
System.arraycopy(uriField, 0, payload, 1, uriField.length); //appends URI to payload
NdefRecord nfcRecord = new NdefRecord(
NdefRecord.TNF_MIME_MEDIA, "text/vcard".getBytes(), new byte[0], payload);
return nfcRecord;
}