Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-nfc-module

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-nfc-module

NFC module in Android for all types of cards NDEF, NDFA & this is an react wrapper for https://github.com/nadam/nfc-reader

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-nfc-module

A NFC Android native module to integrate react-native application

Only Manual Installation

Step 1 : First, install the library from npm

npm install --save react-native-nfc-module

Mostly automatic installation

react-native link react-native-nfc-module

Usage

  1. import NFCScanner from 'react-native-nfc-module';

  2. To check NFC availability

    NFCScanner.NFCavailability( (resp) => {
            if(resp.nfcAvailable == "yes" || resp.nfcAvailable == "no") {
                if(resp.nfcAvailable == "yes")
                this.setState({nfcOpen: true});
    
                this.requestPermission();
            }
        });
    
  3. Listening for NFC events

    step #1

    import {DeviceEventEmitter} from 'react-native';
    

    step #2

    componentDidMount() {
        /*
        Register listener
        */
        DeviceEventEmitter.addListener('onScanned', this.onScanned);
        
        /*
            onload check if there is NFC data 
            
            Caution : For multi window apps, there might be an issue if you dont handle the onResume & onStart events
        */
        NFCScanner.getInitialID("sample");
    }
    
    componentWillUnmount() {
        /*
        Unregister Listener
        */
        DeviceEventEmitter.removeListener('onScanned', this.onScanned);
    }
    

Checklist

Check #1 : Android Manifest.xml NFC permission

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

Check #2 : Register What types of NFC should be handled

```
<activity
        android:name=".MainActivity"
        ... >

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

        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="application/vnd.com.touchon.user"/>
        </intent-filter>

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

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

    </activity>
    ```

Issues

Check #1

this step is not necessary if the android manifest file is added with following dependencies

check "react-native-nfc-module" project --> build.gradle

add following
    compile 'com.google.guava:guava:22.0-android'

should look like

dependencies {
    compile 'com.facebook.react:react-native:+'
    compile 'com.google.guava:guava:22.0-android'
}

else do this

Open Android studio and open android project you will see "react-native-nfc-module" module --> add "File dependency" in Module Settings --> choose "gauvalib.jar"

Keywords

FAQs

Package last updated on 02 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc