react-nativenfchce

How to emulate phone via nfc/hce (React Native) (Android)


I am trying to have a card emulation which does ;

  1. read the card to the phone
  2. use the phone as an NFC card.... I am open to any library advice that helps me do it. and my code is like ; (it is not responding)
import React from 'react';
import { View, Text, StyleSheet, Button } from 'react-native';
import { HceTools } from 'react-native-nfc-sdk';
export default function App () {
    const hce = new HceTools();
    const [isTagRead, setIsTagRead] = React.useState('No');
    const emulate = () => {
        hce.startEmulation(
          {content: 'Hello World!', writable: false},
          () => {
            setTagIsRead('Yes!');
            setTimeout(() => setIsTagRead('No'), 5000);
          }
        )
    }
    return (
        <View>
            <Button onPress={emulate} title="EMULATE NFC TAG" />
            <Text>Was the tag read? {isTagRead}</Text>
        </View>
    );
} 

I tried the block code but it did not respond


Solution

  • Try to use this library for HCE emulation https://github.com/appidea/react-native-hce.