Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Revision as of 18:11, 25 January 2014 by lpvalente (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Ler número serial de tags NDEF (NFC)

From Wiki
Jump to: navigation, search
Article Metadata

Compatibilidade
Plataforma(s):
Series 40

Artigo
Tradução:
Por valderind4
Última alteração feita por lpvalente em 25 Jan 2014

Near Field Communication (NFC) é uma tecnologia de conectividade sem fio de curto alcance que oferece simples, intuita e segura comunicação entre dispositivos eletrônicos. Nokia está ativo na área de NFC, e a empresa lançou o primeiro do mundo em January 2007. Este MIDlet pode ser usado para ler o número serial de uma tag NDEF.

import javax.microedition.contactless.ContactlessException;
import javax.microedition.contactless.DiscoveryManager;
import javax.microedition.contactless.TargetListener;
import javax.microedition.contactless.TargetProperties;
import javax.microedition.contactless.TargetType;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
 
// Uma MIDlet simples para ler o número serial de uma tag NDEF
public class ReadSerial extends MIDlet implements TargetListener {
 
private Form form;
private TextField textField;
 
protected void startApp() throws MIDletStateChangeException {
// Obtém a instância de um NFC Discovery Manager
DiscoveryManager dm = DiscoveryManager.getInstance();
 
// Registra um NDEF_TAG alvo para descoberta
try {
dm.addTargetListener(this, TargetType.NDEF_TAG);
} catch (IllegalStateException e) {
// Catch IllegalStateException
} catch (ContactlessException e) {
// Catch ContactlessException
}
 
// Inicializa e mostra ao usuário os elementos
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) {
// Configura o único identificador do alvo detectado no componente TextField
textField.setString(prop[0].getUid());
}
 
}
This page was last modified on 25 January 2014, at 18:11.
156 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×