我想打一個反應,本機應用程序可以讀取NFC標籤。我正在使用react-native-nfc,但無法正常工作。任何人都可以幫助搞清楚我做錯了什麼,並指出我在正確的方向嗎?讀取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,但不能得到它的工作」,你有任何錯誤消息? 「react-native-nfc」的例子呢,你可以使它工作嗎? – OlivierM
@OlivierM該應用程序被安裝在我的平板電腦和正常工作,我沒有錯誤,但是當我嘗試從卡什麼也沒有發生讀取NFC標籤。我試着用'react-native-nfc'給出的例子,這是同樣的事情。 –
您是否使用第三方應用程序確認平板電腦上的NFC工作? – OlivierM