Results 1 to 11 of 11

Thread: Java and NFC

  1. #1
    nunu is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default Java and NFC

    Hi,

    i hope i have start this thread in the right section.


    I have start with the theme nfc (near field communication) with this code:

    Read serial number of NDEF (NFC) tag - Forum Nokia Wiki

    that was simple.

    But what i have to do, if i have more than one target to analyze?
    For example in than way:
    Java Code:
    public void targetDetected(TargetProperties[] prop) {
    
           if(prop[0].getUid().equals("9816628c")){
    
           form.append("Option1");
           form.append("\\NEXT CHOICE");
    
               if(prop[1].getUid().equals("12e6a1d4")){
               form.append("Option2");
    
                }
                else{
                form.append("FAILTURE2");
                }
           }
           else{
           form.append("FAILTURE");
           }
       }

    In this way the second tag, I can't analyze.

    Any suggestions please ??

    Thx nunu
    Last edited by nunu; 06-29-2010 at 06:41 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    What is that piece of code supposed to do ?
    What more do you want it to do?

    Please use code tags to format your code to preserve indentation.

  3. #3
    nunu is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default

    Sorry

    My aim is to choice, between different tagets.

    How i can format java code?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    f(prop[0].getUid().equals("9816628c")){
    What's a target? Is some part of the above a "target"?

    Put [code ] and [/code ] without spaces around the code.

  5. #5
    nunu is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default

    Thx,


    if(prop[1].getUid().equals("12e6a1d4")){
    is the second target, which choice with the device.
    but the targetlistner works only with prop[0].

    I need to analyzed, one target, after one target.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    TargetProperties[] prop
    The args to the method is an array.
    You can use a loop to look at each element in the array, index from 0 to prop.length-1

    Replace prop[0] with prop[i] where i is the loop index.

  7. #7
    nunu is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default

    This way I have try.

    but every target is set on the first place prop[0].

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    every target is set on the first place prop[0].
    What is a "target"?
    What are in the rest of the elements in prop?

  9. #9
    nunu is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default

    Java Code:
    public class ReadSerial extends MIDlet implements TargetListener {
     
        private Form form;
        private TextField textField;
     
        protected void startApp() throws MIDletStateChangeException {
            // Get instance of NFC Discovery Manager
            DiscoveryManager dm = DiscoveryManager.getInstance();
     
            // Register NDEF_TAG target to discovery
            try {
                dm.addTargetListener(this, TargetType.NDEF_TAG);
            } catch (IllegalStateException e) {
                // Catch IllegalStateException
            } catch (ContactlessException e) {
                // Catch ContactlessException
            }
     
            // Initialize and show user interface elements
            form = new Form("ReadSerial");
            textField = new TextField("Unique identifier:", "", 255, TextField.UNEDITABLE);
            form.append(textField);
            Display.getDisplay(this).setCurrent(form);
        }
     
        protected void pauseApp() {
        }
     
        protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        }
     
        public void targetDetected(TargetProperties[] prop) {
            // Set unique identifier of the detected target on the Text Field
            textField.setString(prop[0].getUid());
        }
     
    }
    this is an example form the Nokia-Forum. (link in the first post)

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Sorry, your question seems to be about how to get info from some hardware device.
    I'm just a java programmer and don't know anything about your hardware.

    You'll have to read the doc for the device to see what to ask it to get the desired info.

  11. #11
    nunu is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default

    Thx

    it is a standard API,
    the connection to the device is build throw the MIDlet and the method targetDetected().

    Connecting isn't a problem. only save the tags(targets).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •