Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    5

    Auto Launch NFC Application and get UID

    Hello, i´m new with java language, so i get the UIDReader example. Now, i liked that the application auto lauch when i touch any tag.

    Can someone help me?

    Thanks, Sérgio Silva

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

    Re: Auto Launch NFC Application and get UID

    Hallo,

    you can use the PushRegistry for this. You can find instructions on how to use the push registry in the NDEFPush example and the documentation of the JSR 257 (and the Nokia extensions).

    br,
    Michael

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    5

    Re: Auto Launch NFC Application and get UID

    Thank´s, now works.

    I´m using the Emulator, and every time i open the emulator when i touch a tag says "Unkown service" with a Stop Image. If i open the application and close, every time i touch a tag the application open automatic. I have permission in Jad file, so it´s necessary open the application in first time?

    Other "problem" is that the first time i touch the time the application open and only with a second touch i can get the UID number. It´s possible with one touch open the application and read the UID number?

    My code is:

    package at.nfcresearch.wima.examples;

    import javax.microedition.contactless.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.contactless.ContactlessException;
    import javax.microedition.contactless.DiscoveryManager;
    import javax.microedition.contactless.TargetProperties;
    import javax.microedition.contactless.TargetListener;
    import javax.microedition.contactless.TargetType;

    public class PushReg extends MIDlet implements TargetListener, CommandListener {

    private Command exitCommand;
    private Form form;

    public PushReg() {

    exitCommand = new Command("Exit", Command.EXIT, 1);
    form = new Form("NFC-Research.at: PushRegistry Start");
    form.addCommand(exitCommand);
    form.setCommandListener(this);

    /*
    * PushRegistry Registration now in JAD File!
    try{
    PushRegistry.registerConnection("ndef:external_rtd?name=urn:nfc:ext:nfc-research.atushreg","at.nfcresearch.wima.examples.PushReg", "*");
    } catch(Exception e) {
    Alert x = new Alert("Unable to Register Push Registry");
    Display.getDisplay(this).setCurrent(form);
    }
    */
    try {
    DiscoveryManager dm = DiscoveryManager.getInstance();
    dm.addTargetListener(this, TargetType.NDEF_TAG);

    } catch (ContactlessException ce) {
    form.append("Unable to register TargetListener: " + ce.toString());
    }


    }

    protected void startApp() {
    Display.getDisplay(this).setCurrent(form);
    }

    protected void pauseApp() {
    }

    protected void destroyApp(boolean bool) {
    }

    public void commandAction(Command cmd, Displayable disp) {
    if (cmd == exitCommand) {
    DiscoveryManager dm = DiscoveryManager.getInstance();
    dm.removeTargetListener(this, TargetType.NDEF_TAG);
    destroyApp(false);
    notifyDestroyed();
    }
    }

    public void targetDetected(TargetProperties[] targetProperties) {

    // in case no targets found, exit the method
    if (targetProperties.length == 0) {
    return;
    }

    // show the UID of the first tag found
    TargetProperties tmp = targetProperties[0];
    form.append("UID read: " + tmp.getUid());
    }
    }

    Bye, Sérgio Silva

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

    Re: Auto Launch NFC Application and get UID

    Hallo,

    Quote Originally Posted by sergiofil View Post
    If i open the application and close, every time i touch a tag the application open automatic. I have permission in Jad file, so it´s necessary open the application in first time?
    With dynamic registration to the PushRegistry..yes, it's necessary to open the application manually for the first time to register the connections in the PushRegistry. But instead of the dynamic registration you can use static registration. In the case of static registration you specify the connections in your application descriptor (JAD). Take a look at this article on the PushRegistry. It explains the PushRegistry and its usage.

    Quote Originally Posted by sergiofil View Post
    It´s possible with one touch open the application and read the UID number?
    As to my knowledge targetListeners will not be invoked on PushRegistry triggered starts. Only NDEFRecordListeners can be immediately invoked by the PushRegistry.

    br,
    Michael

Posting Permissions

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