gpt4 book ai didi

android - 在 React Native 应用程序中读取 NFC 标签

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:43 25 4
gpt4 key购买 nike

我想制作一个可以读取 NFC 标签的 react-native 应用程序。我正在使用 react-native-nfc 但无法正常工作。任何人都可以帮助找出我做错了什么并指出正确的方向吗?

index.android.js 中的代码如下:

import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
ToastAndroid
} from 'react-native';

import NFC, {NfcDataType, NdefRecordType} from "react-native-nfc";

export default class nfcTry extends Component {

constructor(props){
super(props);
}

componentDidMount(){
this.bindNfcListener();
}

bindNfcListener(){
NFC.addListener((payload)=>{
alert(payload.data.id);
})
}

render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
</View>
);
}
}

AndroidManifest.xml 中的代码如下:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nfctry"
android:versionCode="1"
android:versionName="1.0">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.NFC" />

<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />

<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
</intent-filter>

<meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/nfc_tech_filter" />

</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

</manifest>

最佳答案

我终于可以达到目标了!!此时你的全部代码丢失了另一个名为 nfc-ndef-react-native 的 npm 包。 .

将以下包与您现有的代码链接起来,您可能会遇到一些 NDK 问题,也请解决它们!你终于可以做到了!!我现在正在根据需要运行此应用程序。

关于android - 在 React Native 应用程序中读取 NFC 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44265736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com