Push Registry
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MarthinCH.MIDLet;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.wireless.messaging.*;
/**
* @author MA
*/
public class TextMessage extends MIDlet implements CommandListener{
protected static final String kConnection = "sms://:50000";
private Display mDisplay;
private Form mForm;
private Command mExitCommand;
private Command mRegisterCommand, mUnregisterCommand;
public void startApp() {
if(mForm == null){
mForm = new Form("Push MIDlet");
mExitCommand = new Command("Exit", Command.OK, 0);
mRegisterCommand = new Command("Register", Command.OK, 0);
mUnregisterCommand = new Command("Unregister", Command.OK, 0);
mForm.addCommand(mExitCommand);
mForm.addCommand(mRegisterCommand);
mForm.addCommand(mUnregisterCommand);
mForm.setCommandListener(this);
mDisplay = Display.getDisplay(this);
}
mDisplay.setCurrent(mForm);
try{
String[] connections;
connections = PushRegistry.listConnections(false);
if(connections.length > 0){
mForm.append("Registered connections : ");
for(int i=0; i<connections.length; i++)
mForm.append(connections[i]);
}
connections = PushRegistry.listConnections(true);
if(connections.length > 0){
mForm.append("Connections waiting ");
for(int i=0; i<connections.length; i++)
mForm.append(" " + connections[i]);
}
}
catch(Exception e){
mForm.append(e.toString());
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d){
if(c == mExitCommand){
destroyApp(true);
notifyDestroyed();
}
else if(c == mRegisterCommand){
RegisterRunnable rr = new RegisterRunnable(mForm);
Thread t = new Thread(rr);
t.start();
}
else if(c == mUnregisterCommand){
UnregisterRunnable ur = new UnregisterRunnable(mForm);
Thread t = new Thread(ur);
t.start();
}
}
}
class RegisterRunnable implements Runnable{
private Form mForm;
public RegisterRunnable(Form f){
mForm = f;
}
public void run()
{
try{
PushRegistry.registerConnection(TextMessage.kConnection, "Push MIDlet", "*");
mForm.append("Registered !");
}
catch(Exception e){
mForm.append(e.toString());
}
}
}
class UnregisterRunnable implements Runnable{
private Form mForm;
public UnregisterRunnable(Form f){
mForm = f;
}
public void run(){
try{
PushRegistry.unregisterConnection(TextMessage.kConnection);
mForm.append("Unregistered !");
}
catch(Exception e){
mForm.append(e.toString());
}
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MarthinCH.MIDLet;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.wireless.messaging.*;
/**
* @author MA
*/
public class TextMessage extends MIDlet implements CommandListener{
protected static final String kConnection = "sms://:50000";
private Display mDisplay;
private Form mForm;
private Command mExitCommand;
private Command mRegisterCommand, mUnregisterCommand;
public void startApp() {
if(mForm == null){
mForm = new Form("Push MIDlet");
mExitCommand = new Command("Exit", Command.OK, 0);
mRegisterCommand = new Command("Register", Command.OK, 0);
mUnregisterCommand = new Command("Unregister", Command.OK, 0);
mForm.addCommand(mExitCommand);
mForm.addCommand(mRegisterCommand);
mForm.addCommand(mUnregisterCommand);
mForm.setCommandListener(this);
mDisplay = Display.getDisplay(this);
}
mDisplay.setCurrent(mForm);
try{
String[] connections;
connections = PushRegistry.listConnections(false);
if(connections.length > 0){
mForm.append("Registered connections : ");
for(int i=0; i<connections.length; i++)
mForm.append(connections[i]);
}
connections = PushRegistry.listConnections(true);
if(connections.length > 0){
mForm.append("Connections waiting ");
for(int i=0; i<connections.length; i++)
mForm.append(" " + connections[i]);
}
}
catch(Exception e){
mForm.append(e.toString());
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d){
if(c == mExitCommand){
destroyApp(true);
notifyDestroyed();
}
else if(c == mRegisterCommand){
RegisterRunnable rr = new RegisterRunnable(mForm);
Thread t = new Thread(rr);
t.start();
}
else if(c == mUnregisterCommand){
UnregisterRunnable ur = new UnregisterRunnable(mForm);
Thread t = new Thread(ur);
t.start();
}
}
}
class RegisterRunnable implements Runnable{
private Form mForm;
public RegisterRunnable(Form f){
mForm = f;
}
public void run()
{
try{
PushRegistry.registerConnection(TextMessage.kConnection, "Push MIDlet", "*");
mForm.append("Registered !");
}
catch(Exception e){
mForm.append(e.toString());
}
}
}
class UnregisterRunnable implements Runnable{
private Form mForm;
public UnregisterRunnable(Form f){
mForm = f;
}
public void run(){
try{
PushRegistry.unregisterConnection(TextMessage.kConnection);
mForm.append("Unregistered !");
}
catch(Exception e){
mForm.append(e.toString());
}
}
}