- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 NFC 新手,我想将支持 NFC 的安卓手机作为 NFC 标签,并使用 NFC 阅读器读取其数据。如果您能建议我已经构建的用于发送数据的 NFC 应用程序或我应该使用哪种 NFC 读取器硬件,那就太好了。
最佳答案
这是我的 NFC 发送和接收代码。
MainActivity 发送文件
public class MainActivity extends AppCompatActivity {
NfcAdapter nfcAdapter;
private PendingIntent mPendingIntent;
private IntentFilter[] mIntentFilters;
private String[][] mNFCTechLists;
private TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
mTextView = (TextView)findViewById(R.id.recive_text);
PackageManager pm = this.getPackageManager();
// Check whether NFC is available on device
if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
// NFC is not available on the device.
Toast.makeText(this, "The device does not has NFC hardware.",
Toast.LENGTH_SHORT).show();
}
// Check whether device is running Android 4.1 or higher
else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
// Android Beam feature is not supported.
Toast.makeText(this, "Android Beam is not supported.",
Toast.LENGTH_SHORT).show();
}
else {
// NFC and Android Beam file transfer is supported.
Toast.makeText(this, "Android Beam is supported on your device.",
Toast.LENGTH_SHORT).show();
}
// create an intent with tag data and deliver to this activity
mPendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
// set an intent filter for all MIME data
IntentFilter ndefIntent = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
try {
ndefIntent.addDataType("*/*");
mIntentFilters = new IntentFilter[] { ndefIntent };
} catch (Exception e) {
Log.e("TagDispatch", e.toString());
}
mNFCTechLists = new String[][] { new String[] { NfcF.class.getName() } };
}
public void sendFile(View view) {
// Check whether NFC is enabled on device
if(!nfcAdapter.isEnabled()){
// NFC is disabled, show the settings UI
// to enable NFC
Toast.makeText(this, "Please enable NFC.",
Toast.LENGTH_SHORT).show();
startActivity(new Intent(Settings.ACTION_NFC_SETTINGS));
}
// Check whether Android Beam feature is enabled on device
else if(!nfcAdapter.isNdefPushEnabled()) {
// Android Beam is disabled, show the settings UI
// to enable Android Beam
Toast.makeText(this, "Please enable Android Beam.",
Toast.LENGTH_SHORT).show();
startActivity(new Intent(Settings.ACTION_NFCSHARING_SETTINGS));
}
else {
Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
chooseFile.setType("*/*");
chooseFile = Intent.createChooser(chooseFile, "Choose a file");
startActivityForResult(chooseFile, 1);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data!=null) {
Uri uri = data.getData();
nfcAdapter.setBeamPushUris(new Uri[]{uri}, this);
} else {
Toast.makeText(this,"Please choose a file",Toast.LENGTH_SHORT).show();
}
}
public void nextScreen(View view){
startActivity(new Intent(MainActivity.this,SecondActivity.class));
}
public void reciveScreen(View view){
startActivity(new Intent(MainActivity.this,RecieveScreen.class));
}
@Override
public void onNewIntent(Intent intent) {
String action = intent.getAction();
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
String s = action + "\n\n" + tag.toString();
// parse through all NDEF messages and their records and pick text type only
Parcelable[] data = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
if (data != null) {
try {
for (int i = 0; i < data.length; i++) {
NdefRecord[] recs = ((NdefMessage)data[i]).getRecords();
for (int j = 0; j < recs.length; j++) {
if (recs[j].getTnf() == NdefRecord.TNF_WELL_KNOWN &&
Arrays.equals(recs[j].getType(), NdefRecord.RTD_TEXT)) {
byte[] payload = recs[j].getPayload();
String textEncoding = ((payload[0] & 0200) == 0) ? "UTF-8" : "UTF-16";
int langCodeLen = payload[0] & 0077;
s += ("\n\nNdefMessage[" + i + "], NdefRecord[" + j + "]:\n\"" +
new String(payload, langCodeLen + 1,
payload.length - langCodeLen - 1, textEncoding) +
"\"");
}
}
}
} catch (Exception e) {
Log.e("TagDispatch", e.toString());
}
}
mTextView.setText(s);
}
@Override
public void onResume() {
super.onResume();
if (nfcAdapter != null)
nfcAdapter.enableForegroundDispatch(this, mPendingIntent, mIntentFilters, mNFCTechLists);
}
@Override
public void onPause() {
super.onPause();
if (nfcAdapter != null)
nfcAdapter.disableForegroundDispatch(this);
}
}
这是我的接收界面,可能有一些额外的代码,但你可以删除它
public class RecieveScreen extends AppCompatActivity {
private TextView mTextView;
private NfcAdapter mNfcAdapter;
private PendingIntent mPendingIntent;
private IntentFilter[] mIntentFilters;
private String[][] mNFCTechLists;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recieve_screen);
mTextView = (TextView)findViewById(R.id.recieve_tv);
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (mNfcAdapter != null) {
mTextView.setText("Read an NFC tag");
} else {
mTextView.setText("This phone is not NFC enabled.");
}
// create an intent with tag data and deliver to this activity
mPendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
// set an intent filter for all MIME data
IntentFilter ndefIntent = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
try {
ndefIntent.addDataType("*/*");
mIntentFilters = new IntentFilter[] { ndefIntent };
} catch (Exception e) {
Log.e("TagDispatch", e.toString());
}
mNFCTechLists = new String[][] { new String[] { NfcF.class.getName() } };
}
@Override
public void onNewIntent(Intent intent) {
String action = intent.getAction();
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
String s = action + "\n\n" + tag.toString();
// parse through all NDEF messages and their records and pick text type only
Parcelable[] data = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
if (data != null) {
try {
for (int i = 0; i < data.length; i++) {
NdefRecord[] recs = ((NdefMessage)data[i]).getRecords();
for (int j = 0; j < recs.length; j++) {
if (recs[j].getTnf() == NdefRecord.TNF_WELL_KNOWN &&
Arrays.equals(recs[j].getType(), NdefRecord.RTD_TEXT)) {
byte[] payload = recs[j].getPayload();
String textEncoding = ((payload[0] & 0200) == 0) ? "UTF-8" : "UTF-16";
int langCodeLen = payload[0] & 0077;
s += ("\n\nNdefMessage[" + i + "], NdefRecord[" + j + "]:\n\"" +
new String(payload, langCodeLen + 1,
payload.length - langCodeLen - 1, textEncoding) +
"\"");
}
}
}
} catch (Exception e) {
Log.e("TagDispatch", e.toString());
}
}
mTextView.setText(s);
}
@Override
public void onResume() {
super.onResume();
if (mNfcAdapter != null)
mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, mIntentFilters, mNFCTechLists);
}
@Override
public void onPause() {
super.onPause();
if (mNfcAdapter != null)
mNfcAdapter.disableForegroundDispatch(this);
}
}
如果您遇到任何错误,请告诉我。
关于android - 使用支持 NFC 的安卓智能手机作为 NFC 标签并使用 nfc 阅读器接收数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43366875/
我是 NFC 新手,我想将支持 NFC 的安卓手机作为 NFC 标签,并使用 NFC 阅读器读取其数据。如果您能建议我已经构建的用于发送数据的 NFC 应用程序或我应该使用哪种 NFC 读取器硬件,那
我使用ACR122U工具验证Mifare 1K NFC标签时总是失败,但是我可以用Android手机读写这个标签。 ACR122U Load Authentication Keys 90 00 6
我对 NFC 标准的概述有一些问题。 我所知道的是: ISO/IEC 14443是感应卡的标准,使用 RFID 作为通信协议(protocol); ISO/IEC 18092 (NFCIP-1) 是
我正在尝试实现一个基于通用 NFC 标签的授权系统。我想解决的问题之一是标签克隆。我读过一些文献,通过使用在制造过程中写在标签上的只读标签 ID 来确保标签的真实性。此 ID 由所有者签名并写在标签上
我想为使用 RFID 实现多项功能的系统提案指定设备。它可能会在未来扩展到包括交易,所以我正在努力寻找合适的技术来使用。 计划是使用被动卡。 HF/NFC 卡/读卡器以相同的频率运行,但它们可以互换使
我有一个 ACR122U 阅读器,可以读取很多标签,但不能读取 ICODE SLIX SL2S2002 标签。为什么会这样?我已经在移动设备上尝试过该标签,它被识别出来了。 最佳答案 ICODE SL
NFC Host Card Emulation mode摆脱了本地安全元件 (SE),并通过利用存储在云中的 SE 来促进支付,使用 cooperation几个参与方,例如商家、服务、提供商、发卡机构
Mifare (S50) 1K NFC 卡有 16 个扇区,每个扇区有 4 个 block ,每个 block 保存 16 字节数据。 每个扇区的最后一个 block 是扇区尾部,其中 KeyA 和
我创建的系统存在一些问题。 在登录屏幕等特定页面上,我接受 NFC 卡刷卡以读取 ID 并让用户登录 但是,当用户在未编码 NFC 的页面上扫描卡时,Android 设备会自动最小化我的应用程序并显示
我正在尝试使用 NFC 从血糖仪读取数据,目前在 Android 上,还没有尝试过 iOS(没有带 NFC 的手机)。 我正在使用 react-native-nfc-manager 作为库和它附带的示
这个问题专门针对 MIFARE Ultralight C/EV1,或 MIFARE DESFire EV1,甚至 NTAG 卡。我想实现一个 token 系统,这样每次普通用户读取其中一张卡片时,他们
考虑一名员工使用 NFC 安卓设备通过读取固定在墙上的非接触式 javacard 来报告他的位置,每个人都可以访问。 员工用智能手机扫描javacard,只发送时间戳 非接触式 javacard 接收
有没有办法让 NFC 应用程序读取标签,而不是可以在手机上下载的所有其他应用程序? 通常,如果有多个应用程序可以读取给定标签,系统会提示用户打开哪个应用程序。我想跳过这一步,让我的应用程序自动打开。
我想让我的安卓设备充当 NFC 标签。是否可以使用 NFC 设备作为 NFC 标签?我怎样才能做到这一点?我已经完成了读/写标签,设备之间的光束数据。 最佳答案 这可能是可行的,具体取决于您的 NFC
如果我有 NFC 读取器/写入器设备,我能否让它检测我的支持 NFC 的 Android 手机,以便我可以将数据从我的手机传输到该设备?我在 Stackoverflow 上找到了一些与卡模拟相关的链接
我在 SO 上看到很多关于 NFC 的问题,我遇到的最接近的问题是 Can an Android NFC phone act as an NFC tag? 然而,这个问题是一年多前提出的,当时 Gal
我有一台搭载 Android 4.2 的 Android 平板电脑。此平板电脑没有 NFC 硬件。但是我有一个外部 USB 读卡器:ACR 1252U , 带有 Android library .不幸
据我目前了解,NFC 手机将充当 NFC 阅读器,从 NFC 标签读取数据。现在我的问题是,我们可以改变这个吗?我们能否让 Android NFC 手机充当 NFC 读取器从中获取数据的标签? 感谢您
我被搜索了有关 NFC SIM 卡的信息,发现 such explanations关于他们在这里和那里: For those who want to use near field communicat
Core NFC 是否适用于 iPad? 综上所述,iPad does have NFC chips ,但 Core NFC documentation不说它支持它。 Note Reading NFC
我是一名优秀的程序员,十分优秀!