use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class NfcMidlet2 method addTransactionListener.
public void addTransactionListener() {
SecureElementManager sem = SecureElementManager.getInstance();
if (sem == null) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:SecureElementManager instance is null - exiting");
return;
}
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:getting SecureElement instance of type SIM");
SecureElement se = null;
try {
se = sem.getSecureElement(SecureElement.SIM);
} catch (Exception e1) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:exception when getting SE: " + e1.getClass().getName() + ":" + e1.getMessage());
}
if (se == null) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:SecureElement(SIM) is null - exiting");
return;
}
myListener = getTransactionListener();
try {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:adding transaction listener");
try {
se.addTransactionListener(myListener, MY_AID);
} catch (NFCException e) {
if (e.getMessage().startsWith("TransactionListener has already been added") || e.getMessage().startsWith("AID has already been registered")) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:already registered - ignoring");
}
}
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:added transaction listener OK");
} catch (Exception e) {
if (!e.getMessage().startsWith("TransactionListener has already been added") && !e.getMessage().startsWith("AID has already been registered")) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:exception when adding transaction listener: " + e.getClass().getName() + ":" + e.getMessage());
return;
} else {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:exception when adding transaction listener: " + e.getClass().getName() + ":" + e.getMessage());
return;
}
}
try {
se.setTechnologyTypes(SecureElement.BATTERY_ON_MODE, TechnologyType.ISO14443B);
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:NFC routing established OK");
} catch (NFCException e) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:exception when setting technology types: " + e.getClass().getName() + ":" + e.getMessage());
}
try {
runtimeStore.replace(TRANSACTION_LISTENER, myListener);
} catch (IllegalArgumentException e) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " RuntimeStore.replace exception: " + e.getClass().getName() + ":" + e.getMessage());
}
}
use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class GameScreen method gameWon.
private void gameWon() {
game_state.lockBoard();
// we may already be listening so remove the NDEF listener in anticipation of adding it
proto.stopListeningForMessages();
// again shortly
setStatusMessage(Constants.WINNER_MESSAGE, true);
int[] win_line = game_state.getWinningLine(_symbol);
if (_symbol == Constants.PLAYER_SYMBOL_CROSS) {
win_line_bmp = BitmapFactory.addStateIndicator(cross_unfocused, Constants.WIN_LINE_COLOUR);
} else {
win_line_bmp = BitmapFactory.addStateIndicator(nought_unfocused, Constants.WIN_LINE_COLOUR);
}
for (int i = 0; i < 3; i++) {
tiles[win_line[i]].setImage(win_line_bmp);
}
game_state.setGame_over(true);
my_bid = new ProtocolMessageMasterBid();
try {
proto.sendMasterBid(my_bid);
proto.listenForMessages();
} catch (NFCException e) {
Utilities.log("XXXX " + e.getClass().getName() + ":" + e.getMessage());
setStatusMessage("It didn't work, please try again");
}
Utilities.popupMessage("You have won!");
}
use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class StartGameScreen method gameMessage.
public void gameMessage(ProtocolMessage message) {
if (message instanceof ProtocolMessageMasterBid) {
ProtocolMessageMasterBid other_bid = (ProtocolMessageMasterBid) message;
int device_status = 0;
boolean initialised = false;
if (my_bid.getBid() > other_bid.getBid()) {
Utilities.log("XXXX won the bid: player 1");
device_status = Constants.PLAYER_1;
initialised = true;
} else {
if (my_bid.getBid() < other_bid.getBid()) {
Utilities.log("XXXX lost the bid: player 2");
device_status = Constants.PLAYER_2;
initialised = true;
} else {
Utilities.popupMessage("It didn't work, try again!");
}
}
if (initialised) {
try {
proto.disableMessaging();
} catch (NFCException e) {
Utilities.log("XXXX StartGameScreen:" + e.getClass().getName() + ":" + e.getMessage());
Utilities.popupMessage("We had a problem, please try again");
}
final int player_no = device_status;
final MainScreen next_screen;
if (player_no == Constants.PLAYER_2) {
next_screen = GameScreen.getInstance(player_no);
} else {
next_screen = new SymbolSelectionScreen();
}
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(next_screen);
}
});
}
}
}
use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class NfcSender method buildNDEFMessages.
public NDEFMessage[] buildNDEFMessages() {
Utilities.log("XXXX NfcSender sending ProtocolMessage:" + _message);
NDEFMessage[] ndef_messages = null;
NDEFMessage game_message;
try {
byte[] payload = _message.marshall();
Utilities.log("XXXX NfcSender sending payload 0x" + ByteArrayUtilities.byteArrayToHex(payload));
game_message = NDEFMessageUtils.createExternalTypeMessage(Constants.SNEP_DOMAIN, Constants.SNEP_TYPE, payload);
ndef_messages = new NDEFMessage[] { game_message };
} catch (NFCException e) {
Utilities.log("XXXX NfcSender:" + e.getClass().getName() + ":" + e.getMessage());
}
return ndef_messages;
}
Aggregations