Git Product home page Git Product logo

Comments (2)

floutchito avatar floutchito commented on July 25, 2024

Hello,

As I was testing this possibility, I think I found the answer : NO.

Consider these listeners :

nfc.addMimeTypeListener(
    'app/bt',
    app.firstCallback,
    function() {
        console.log( "Listening for NDEF mime tags with type app/bt." );
    },
    function(){
        throw new appError( "Error establishing NDEF MimeType listener" );
    }
);

nfc.addMimeTypeListener(
    'app/ty',
    app.secondCallback,
    function() {
        console.log( "Listening for NDEF mime tags with type app/ty." );
    },
    function(){
        throw new appError( "Error establishing NDEF MimeType listener" );
    }
);

Adding 2 MimeType listeners in a deviceReady function executes the 2 callback functions when detecting a tag containing a 'app/bt' MimeType record, and no 'app/ty' MimeType record.

Do you think I misunderstood anything, or is it the 'normal' behaviour of the plugin ?

from phonegap-nfc.

don avatar don commented on July 25, 2024

The plugin was designed to have registerMimeType called one time, but it can be called for multiple mime types.

phonegap-nfc doesn't pass return values through the success callback like may phonegap plugins (this is a legacy issue from phonegap 0.9.x)

nfc.addMimeTypeListener registers event listener for javascript ndef-mime events

var nfc = {

    addMimeTypeListener: function (mimeType, callback, win, fail) {
        document.addEventListener("ndef-mime", callback, false);
        cordova.exec(win, fail, "NfcPlugin", "registerMimeType", [mimeType]);
    },

    ...

With Android 4.x is you use the same listener for multiple mimetypes, it appears to work OK and the listener is only called once.

    nfc.addMimeTypeListener("text/json", onNfc, success, failure);
    nfc.addMimeTypeListener("text/demo", onNfc, success, failure);

If you use different listeners BOTH listeners are called every time.

    nfc.addMimeTypeListener("text/json", onNfc, success, failure);
    nfc.addMimeTypeListener("text/demo", onNfc2, success, failure);

This is because the native Android code registers a filter for the mime type but throws the same ndef-mime javascript event for every tag.

from phonegap-nfc.

Related Issues (20)

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.