Git Product home page Git Product logo

Comments (16)

Skielex avatar Skielex commented on July 25, 2024

Is this something that is being worked on?

from phonegap-nfc.

don avatar don commented on July 25, 2024

Not actively. Do you need it? Which platform?

from phonegap-nfc.

Skielex avatar Skielex commented on July 25, 2024

I'm working on a project in which we're considering using PhoneGap and this NFC plug-in as a part of the solution. We want to be able to lock tags. Right now Android seems like the platform to go with since we don't have any interest in Blackberry, WP8 doesn't support locking tags and iOS doesn't even support NFC.

Make read-only support for Android could very easily be added (see code below). However, is seems like the plug-in code base might be undergoing some big changes. Thus I'm not sure if you'd like me to try and commit these addition.

NfcPlugin.java

    private void eraseTag(CallbackContext callbackContext) throws JSONException {
        Tag tag = savedIntent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        NdefRecord[] records = {
            new NdefRecord(NdefRecord.TNF_EMPTY, new byte[0], new byte[0], new byte[0])
        };
        writeNdefMessage(new NdefMessage(records), tag, callbackContext, false);
    }

    private void writeTag(JSONArray data, CallbackContext callbackContext) throws JSONException {
        if (getIntent() == null) {  // TODO remove this and handle LostTag
            callbackContext.error("Failed to write tag, received null intent");
        }

        Tag tag = savedIntent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        NdefRecord[] records = Util.jsonToNdefRecords(data.getString(0));
        boolean makeRealOnly = data.optBoolean(1);
        writeNdefMessage(new NdefMessage(records), tag, callbackContext, makeRealOnly);
    }

    private void writeNdefMessage(final NdefMessage message, final Tag tag, final CallbackContext callbackContext, final boolean makeReadOnly) {
        cordova.getThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Ndef ndef = Ndef.get(tag);
                    if (ndef != null) {
                        ndef.connect();

                        if (ndef.isWritable()) {
                            int size = message.toByteArray().length;
                            if (ndef.getMaxSize() < size) {
                                callbackContext.error("Tag capacity is " + ndef.getMaxSize() +
                                        " bytes, message is " + size + " bytes.");
                            } else {        
                                ndef.writeNdefMessage(message);
                                if(makeReadOnly) {
                                    ndef.makeReadOnly(); // canMakeReadOnly() returns false for I-CODE tags even though makeReadOnly works fine
                                }
                                callbackContext.success();
                            }
                        } else {
                            callbackContext.error("Tag is read only");
                        }
                        ndef.close();
                    } else {
                        NdefFormatable formatable = NdefFormatable.get(tag);
                        if (formatable != null) {
                            formatable.connect();
                            if(makeReadOnly) {
                                formatable.formatReadOnly(message);
                            } else {
                                formatable.format(message);
                            }
                            callbackContext.success();
                            formatable.close();
                        } else {
                            callbackContext.error("Tag doesn't support NDEF");
                        }
                    }
                } catch (FormatException e) {
                    callbackContext.error(e.getMessage());
                } catch (TagLostException e) {
                    callbackContext.error(e.getMessage());
                } catch (IOException e) {
                    callbackContext.error(e.getMessage());
                }
            }
        });
    }

phonegap-nfc.js

    write: function (ndefMessage, win, fail, makeReadOnly) {
        cordova.exec(win, fail, "NfcPlugin", "writeTag", [ndefMessage, makeReadOnly]);
    },

from phonegap-nfc.

ashish447 avatar ashish447 commented on July 25, 2024

My application i is attendance system i want to nfc tag read -write protected for me and read proteted for other
how it implement tell me

from phonegap-nfc.

JohnMcLear avatar JohnMcLear commented on July 25, 2024

@ashish447 this isn't available right now, you can attempt to add it yourself by editing the Nfcplugin.java file with the code above but if I was you I'd wait for @don to implement it. Alternatively you can make the chagnes to teh NfcPlugin.java file and open a pull request with your changes in.

from phonegap-nfc.

ashish447 avatar ashish447 commented on July 25, 2024

JohnMcLear thanks .u know about Rfid card tag i have nexsus 7 device but it can't read Rfid Card
jaycon_systems_white_rfid_card_125khz

what specification of rfid tag

from phonegap-nfc.

mcotter avatar mcotter commented on July 25, 2024

Hi,

Is there any time line for this to be added in? Would be very useful for a project we are looking to start.

Cheers
Mark

from phonegap-nfc.

ashish447 avatar ashish447 commented on July 25, 2024

what You want to say ?

On Wed, Dec 4, 2013 at 8:08 PM, mcotter [email protected] wrote:

Hi,

Is there any time line for this to be added in? Would be very useful for a
project we are looking to start.

Cheers
Mark


Reply to this email directly or view it on GitHubhttps://github.com//issues/6#issuecomment-29809347
.

from phonegap-nfc.

ashish447 avatar ashish447 commented on July 25, 2024

You are hiring Project

On Wed, Dec 4, 2013 at 10:07 PM, Ashish Kasodariya <
[email protected]> wrote:

what You want to say ?

On Wed, Dec 4, 2013 at 8:08 PM, mcotter [email protected] wrote:

Hi,

Is there any time line for this to be added in? Would be very useful for
a project we are looking to start.

Cheers
Mark


Reply to this email directly or view it on GitHubhttps://github.com//issues/6#issuecomment-29809347
.

from phonegap-nfc.

mcotter avatar mcotter commented on July 25, 2024

@ashish447 Just wondering if the functionality is going to be added into the plugin?

from phonegap-nfc.

don avatar don commented on July 25, 2024

I'll try to get this in the next round of fixes.

from phonegap-nfc.

mcotter avatar mcotter commented on July 25, 2024

@don that would be great. If there is anything I can do to help let me know and I will do my best. cheers

from phonegap-nfc.

don avatar don commented on July 25, 2024

http://developer.android.com/reference/android/nfc/tech/Ndef.html#makeReadOnly()

from phonegap-nfc.

maran001 avatar maran001 commented on July 25, 2024

@don, i am working on a project where i have to write the data to the tag and then if someone tries to read the tag, user has to provide the pin. Reading and writing the tag is not an issue, issue is if someone want to read the tag after first time write, pin should be required. Do you have any suggestions how i can achieve this.

from phonegap-nfc.

maran001 avatar maran001 commented on July 25, 2024

@don, i also tried to encrypt the payload using my unique AES key and decrypt using the same key to protect my payload.

from phonegap-nfc.

zhimeng9 avatar zhimeng9 commented on July 25, 2024

hi don, do we have an API to set password to protect the NFC tag, such as the function which is python version http://nfcpy.org/latest/modules/tag.html#nfc.tag.Tag.protect ?

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.