×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    13

    Is this possible?

    Hey,

    I wrote a tag with my NFC phone with a special link: http://www.website.com/index.php?data=hello
    Now I want to make a midlet that's going to do the following when you start it:

    - Ask to fill in my telephonenumber: Yes that's possible
    - Wait for the user to read the tag: Yes that's possible
    - When it reads the tag, it should see the link but then I want to add to this link: "&number=xxxx"
    - Go to the complete url (with the number part added)

    Is this possible? Who can help me a bit starting out...

  2. #2
    Registered User
    Join Date
    Feb 2009
    Location
    Hagenberg, Austria
    Posts
    121

    Re: Is this possible?

    Hallo,

    Quote Originally Posted by Astar View Post
    Now I want to make a midlet that's going to do the following when you start it:

    - When it reads the tag, it should see the link but then I want to add to this link: "&number=xxxx"
    If you used an NDEF URI record for storing the URL on the tag, you can read the NDEFMessage from the tag with the readNDEF() method (the JavaDoc on JSR-257 has a nice example on this) and then extract the NDEFRecord. From the NDEFRecords payload you reconstruct the URL:
    - The first byte is the identifier code, i.e. a coded prefix that needs to be prepended to the URI (e.g. 0x00=no prefix, 0x01="http://www.", 0x03="http://")
    - The remainder is the URI without the prefix.

    => Thus, you just need to append the prefix string to the remainder string.
    Then you can also append the string "&number=<...>".

    Quote Originally Posted by Astar View Post
    - Go to the complete url (with the number part added)
    See Open Web Browser through Java

    br,
    Michael

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    13

    Re: Is this possible?

    Thank you for your answer. I'm playing around with some code now, but I keep getting the following error:

    Code:
    java.lang.NullPointerException
    ContactlessEventHandler:: event handler error: null
    I execute the code on the nokia simulator and when I try to read a MiFare card, I get this error... Do you have any idea why this is?

    The relevant piece of code is:

    Code:
        public void targetDetected(TargetProperties[] prop) {
            // Select first found target
            TargetProperties target = prop[0];
            // check that target type is NDEF_TAG
            TargetType[] types = target.getTargetTypes();
            for (int i=0; i<types.length; i++) {
                if (types[i].equals(TargetType.NDEF_TAG)) {
                    try {
                        // Get URL to open the connection
                        String url = target.getUrl();
                        // Open NDEFTagConnection to the target
                        conn = (NDEFTagConnection)Connector.open(url);
                        // Read data from the target
                        NDEFMessage message = conn.readNDEF();
                        NDEFRecord[] records = message.getRecords();
    
                        System.out.println("Length: " + records.length); // this doesn't even show up...
                        for (int j=0; j<records.length; j++) {
                            System.out.println(records[j]);
                        }
                    }
                    catch (IOException ioe) {
                    // Handle exception
                    }
                    catch (ContactlessException ce) {
                    // Handle exception
                    }
                }
                else {
                i++;
                }
            }
        }

  4. #4
    Registered User
    Join Date
    Feb 2009
    Location
    Hagenberg, Austria
    Posts
    121

    Re: Is this possible?

    Hallo,

    Quote Originally Posted by Astar View Post
    Code:
    java.lang.NullPointerException
    ContactlessEventHandler:: event handler error: null
    Do you have any idea why this is?
    No, I don't but I have some comments on your code...

    Quote Originally Posted by Astar View Post
    Code:
    TargetType[] types = target.getTargetTypes();
    for (int i=0; i<types.length; i++) {
      if (types[i].equals(TargetType.NDEF_TAG)) {
    For the NDEFTagConnector you can go more simple than that:
    Code:
    String url = target.getUrl();
    if (url != null) {
      //now you know there's NDEF data on the tag
      // Open NDEFTagConnection to the target
      conn = (NDEFTagConnection)Connector.open(url);
    Quote Originally Posted by Astar View Post
    Code:
    else {
      i++;
    }

    You should avoid incrementing the counter variable of a for-statement outside the for-statement's loop-expression. Anyways, I'm not sure what you are trying to accomplish with this.

    br,
    Michael

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    13

    Re: Is this possible?

    Hey!

    I got something to work now, but I need some more help...

    Now my code does this:
    - Ask phonenumber
    - read tag UID

    Now I want to know if it is possible to write just some raw data on the tag? Something like: "D93XIWO299" and not an URL. I want to make my code go to a fixed URL, so I don't need to write a complete webadres on the tag... I will add this raw data from every different tag to a fixed url, programmed in my midlet.

    Is that possible??

    I found something about text RTD? Check page 9 @ http://www.maintag.fr/fichiers/pdf-f...d-text-1-0.pdf
    How do I do that? How do I get that on the tag?

    Greetz!
    Last edited by Astar; 2010-08-03 at 14:06.

  6. #6
    Registered User
    Join Date
    Feb 2009
    Location
    Hagenberg, Austria
    Posts
    121

    Re: Is this possible?

    Hallo Astar,

    Of course you can also write some raw data on a tag. But in the case of direct access to the tag, the API is not independent from the tag type.
    * NXP MIFARE Classic: com.nokia.nfc.nxp.mfstd
    * NXP MIFARE Ultralight (Forum Type 2): com.nokia.nfc.nxp.simpletag
    * Innovision Jewel Tag (Forum Type 1): com.innovision.rf

    As this solution depends on the tag type and on a Nokia-specific API, I would suggest you still stick to the NDEF format. The NDEF API is standardized and idependent from the tag type. Instead of using the Text RTD I would suggest you define your own custom record type. That way, you do not need to care about any of the elements introduced by the Text RTD (i.e. status byte, language code, text encoding)
    Something like this creates a new record type object and a new record of that type:

    Code:
    NDEFRecordType t = new NDEFRecordType(NDEFRecordType.EXTERNAL_RTD, "nfc-research.at:code");
    // the record type name "nfc-research.at:code" specifies the record type. External RTD names
    // follow the format "<your-domain-name>:<type name>".
    
    byte[] data = {(byte) 0x44, (byte) 0x39, (byte) 0x33, (byte) 0x58, 
                   (byte) 0x49, (byte) 0x57, (byte) 0x4F, (byte) 0x32,
                   (byte) 0x39, (byte) 0x39}; //D93XIWO299
    NDEFRecord r = new NDEFRecord(t, null, data);
    br,
    Michael

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    13

    Re: Is this possible?

    Ok, thanks! I will use the NDEF format now!
    Last edited by Astar; 2010-08-05 at 09:41. Reason: new post, moderator helped me

Posting Permissions

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