Giter Club home page Giter Club logo

capacitor-nfc-launch's Introduction

npm version capacitor support

capacitor-nfc-launch

This plugin reads the message of a self-written NFC tag. Just tap the device on a NFC tag and you will get the response in the 'message' listener. Your app will also start automatically and trigger the event listener.

Supported platforms

Platform Supported
Android
iOS
Web

Install

npm i capacitor-nfc-launch
npx cap sync android

AndroidManifest.xml

<intent-filter android:autoVerify="true">
    <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
    <category android:name="android.intent.category.DEFAULT" />
    // The plugin will only fire the event, if a NFC tag with this Content-Type has been sent
    <data android:mimeType="application/APPBUNDLEID" />
</intent-filter>

How to write the tag

Download and open the app NFC Tools. Choose 'write' and add a dataset of the type 'data' (last entry in list). Content-Type: application/APPBUNDLEID Data: 'My example data'

Usage

app.component.ts

import { NFCLaunch } from 'capacitor-nfc-launch';

if (Capacitor.isNativePlatform()) {
  NFCLaunch.addListener('message', (data: any) => {
    console.log(data.message); // Outputs: My example data
  });
}

API

addListener('message', ...)

addListener(eventName: 'message', listenerFunc: MessageListener) => Promise<PluginListenerHandle> & PluginListenerHandle

Add a listener to a NFC message event

Param Type
eventName 'message'
listenerFunc MessageListener

Returns: any


removeAllListeners()

removeAllListeners() => any

Removes all listeners.

Returns: any


Interfaces

PluginListenerHandle

Prop Type
remove () => any

Type Aliases

MessageListener

(response: any): void

capacitor-nfc-launch's People

Contributors

nepheus avatar

Stargazers

 avatar

Watchers

 avatar  avatar

capacitor-nfc-launch's Issues

Cannot read any NFC

Hi I tried to use this plugin. I was able to run the app but in doesn't scan any NFC.

here's my AndroidManifest.xml:
image

and my home.page.ts:
image

Did I missed anything?

null object reference error when opening the app by clicking an unrelated (to NFC) push notification

This add-on is helpful, and works in providing the tag data in the message object, as intended. However, I am encountering a side-effect. When trying to open the app from a (unrelated to NFC) notification, this add-on throws an error preventing the app from launching. Here's the logcat trace:

2022-06-21 09:52:40.732 18377-18377/RemovedBundleID E/AndroidRuntime: FATAL EXCEPTION: main
Process:RemovedBundleID, PID: 18377
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at nepheus.capacitor.nfclaunch.NFCLaunchPlugin.handleOnNewIntent(NFCLaunchPlugin.java:22)
at com.getcapacitor.Bridge.onNewIntent(Bridge.java:1037)
at com.getcapacitor.BridgeActivity.onNewIntent(BridgeActivity.java:228)
at android.app.Activity.performNewIntent(Activity.java:8070)
at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1441)
at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1454)
at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:3904)
at android.app.ActivityThread.handleNewIntent(ActivityThread.java:3911)
at android.app.servertransaction.NewIntentItem.execute(NewIntentItem.java:56)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2253)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7870)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

This error happens regardless of whether this add-on is imported or not. As long as it is installed, this error is encountered. If I uninstall it, the error goes away.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.