×

Discussion Board

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

    Nokia bookmark, ndef format??

    I fixed the nullpointer problem. It all works on the emulator now... BUT it doesn't work on the phone...

    I created a midlet (emulator mode) which writes a webaddress on a tag, reads the tag and visits the webadress on the tag. But now I uploaded the midlet to my phone, put a bookmark on a real tag (with nokia phone) and tried to read it with my midlet to visit that bookmark. The phone didn't browse to that bookmark, and later I found out why.
    The data on the tag consists of a series of random characters + the title of the webpage + random characters + the webaddress + random characters...

    When I used my midlet & emulator to write the webaddress on the tag, I didn't include a title, only the address...
    byte[] urlBytes = "http://www.test.com".getBytes();
    NDEFRecord r = new NDEFRecord(new NDEFRecordType(NDEFRecordType.NFC_FORUM_RTD, "urn:nfc:wkt:U"), null, null);
    ...
    So that explains why my midlet doesn't understand the data on the tag, written by the nokia phone...

    How do I read the format that a nokia phone writes to a tag? I just want to visit the bookmark...
    Last edited by Astar; 2010-08-09 at 14:47. Reason: problem...

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

    Re: Nokia bookmark, ndef format??

    Hallo Astar,

    I haven't tested this, but from your explainaition I would believe that the Nokia phone uses a Smart Poster record instead of a plain URI record. See the Smart Poster RTD specification (here) on how such a record is composed.

    The Smart Poster record (urn:nfc:wkt:Sp) is a container for several NDEF records, i.e. the payload of the Smart Poster record is, again, an NDEF message. This nested NDEF message contains exactly one URI record and may contain several other records, like a text record that holds the bookmark's name.

    Therefore, if you use a Smart Poster record, you have to extract the nested NDEF message from its payload first (you can do this with the getNestedNDEFMessage() method of the NDEFRecord object.) In this new NDEF message you have to search for the URI record. This URI record contains the URL that you expected before.

    But there is also one thing you have when using Smart Poster records: On the Nokia phones you cannot use Smart Poster records with the push registry to start your own MIDlets.

    br,
    Michael

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

    Re: Nokia bookmark, ndef format??

    Thanks!!!!!

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

    Re: NDEF Read = nullpointerexception?

    My application works now, but I have 1 small problem.

    Reading and writing a tag is no problem, but reading a tag twice gives me a InterruptedIOException: target lost

    I already made sure the connection isn't opened twice...

    Code:
    // Get URL to open the connection
                        String url = target.getUrl();
                        // Open NDEFTagConnection to the target
                        if(conn == null)
                        {
                            conn = (NDEFTagConnection)Connector.open(url);
                        }
                        // Read data from the target
                        NDEFMessage message = conn.readNDEF();
                        NDEFRecord[] records = message.getRecords();
    Why is that? How do I fix it?

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

    Re: NDEF Read = nullpointerexception?

    Hallo Astar,

    I doubt that the exception is caused by this piece of code. What else do you do inside the targetDetected handler? Which line of code throws the exception?

    br,
    Michael

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

    Re: Nokia bookmark, ndef format??

    Code:
    public void targetDetected(TargetProperties[] targetProperties) {
                      // ...
    
                        try {
                        String url = target.getUrl();
                        if(conn == null){
                             // if the target is detected for the second time, this part will be skipped.
                            conn = (NDEFTagConnection)Connector.open(url);
                        }
                        NDEFMessage message = conn.readNDEF();
                        NDEFRecord[] records = message.getRecords();
                    }
                    catch (IOException ioe) {
                        // Handle exception               
                    }
            }
    }
    Last edited by Astar; 2010-08-11 at 09:21.

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

    Re: Nokia bookmark, ndef format??

    Hallo Astar,

    So I guess the exception is raised by this line of code:
    Code:
    NDEFMessage message = conn.readNDEF();
    Is there any specific reason why you try to skip opening the connection on the second targetDetected event?
    Code:
    if(conn == null){
        // if the target is detected for the second time, this part will be skipped.
        conn = (NDEFTagConnection)Connector.open(url);
    }
    What happens now is that during your second targetDetected event, you try to access the previous connection to the NDEF tag. As that connection has been (forcefully) terminated by removing the tag from the reader, the conn object is no longer valid.

    Each targetDetected event is triggered by bringing the tag in range of the phone. To achieve this, you have to move the tag out of range and then bring it in range again. This causes the connection to the tag to be completely reinitialized (i.e. the tag is powered down and the powered on again and a new connection to the tag is established).

    Consequently with every targetDetected event you have to open a new connection to the tag (and when you are finished with reading/writing the tag you have to close the connection again.

    br,
    Michael

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

    Re: Nokia bookmark, ndef format??

    You were right! I had to close the connection first. Thanks again mroland!!!

Similar Threads

  1. NDEF format
    By loicmormont in forum Near Field Communication
    Replies: 4
    Last Post: 2009-08-06, 13:32
  2. Read-Only NDEF Message on NFC Forum tag
    By Pybel in forum Near Field Communication
    Replies: 0
    Last Post: 2009-07-27, 16:37
  3. APDU and NDEF
    By praghuna in forum Near Field Communication
    Replies: 2
    Last Post: 2008-12-20, 14:39
  4. NDEF security
    By matdacat in forum Near Field Communication
    Replies: 0
    Last Post: 2007-07-19, 07:35
  5. NDEF and Mifare
    By cgauld in forum Near Field Communication
    Replies: 1
    Last Post: 2007-07-09, 13:14

Posting Permissions

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