PushRegistry nao funciona o registerAlarm

1 resposta
duardor

Alguem pode me ajudar?
Simplesmente o PushRegistry nao ativa o MIDlet...
Ele nao está mais rodando tb (jah chamei notifyDestroyed) ...
Nao to entendendo...
É uma aplicação simples de alarme...
Estou usando o wireless toolkit da sun:

Alarme.java
import java.util.Date;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.io.PushRegistry;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class Alarme extends MIDlet implements CommandListener {
	
	Form formAlarme;
	DateField date;
	Display tela;
	
	protected void startApp() throws MIDletStateChangeException {
		long time = 0;
		try {
			time = PushRegistry.registerAlarm(this.getClass().getName(),
					new Date().getTime());
		} catch (ConnectionNotFoundException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		tela = Display.getDisplay(this);
		Date agora = new Date();
		date = new DateField("Alarme em:", DateField.DATE_TIME);
		date.setDate(agora);
		System.out.println("Agora sao: " + agora.getTime());
		formAlarme = new Form("Alarme", new Item[]{date});
		formAlarme.addCommand(new Command("Cancel", Command.CANCEL, 1));
		formAlarme.addCommand(new Command("Ok", Command.OK, 1));
		formAlarme.setCommandListener(this);
		if (time == 0) {
			try {
				PushRegistry.registerAlarm(this.getClass().getName(), 0);
			} catch (ConnectionNotFoundException e1) {
				e1.printStackTrace();
			} catch (ClassNotFoundException e1) {
				e1.printStackTrace();
			}
			tela.setCurrent(formAlarme);
		} else {
			System.out.println("Estava registrado para dar alarme em: " + time);
			doAlarm();
		}
	}
	
	protected void pauseApp() {
	}
	
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
	}
	
	public void commandAction(Command c, Displayable d) {
		int commandType = c.getCommandType();
		if (commandType == Command.CANCEL) {
			notifyDestroyed();
		} else if (commandType == Command.OK) {
			setAlarm();
		}
	}
	private void setAlarm() {
		System.out.println("Inicio setAlarm");
		System.out.println("Agora sao: " + new Date().getTime());
		System.out.println("Ira ser agendado para: " + date.getDate().getTime());
		final String nome = this.getClass().getName();
		new Thread() {
			public void run() {
				try {
					PushRegistry.registerAlarm(nome, date.getDate().getTime());
				} catch (ConnectionNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println("Alarme setado!");
			}
		}.start();
		System.out.println("Fim setAlarm");
	}
	private void doAlarm() {
		System.out.println("Comecou o alarme!");
		Alert alarme = new Alert("ALARME!!!");
		alarme.setTimeout(Alert.FOREVER);
		tela.setCurrent(alarme, formAlarme);
		System.out.println("Acabou o alarme!");
	}
}
Alarme.jad
MIDlet-1: Alarme, Alarme.png, Alarme
MIDlet-Jar-Size: 2246
MIDlet-Jar-URL: Alarme.jar
MIDlet-Name: Alarme
MIDlet-Permissions: javax.microedition.io.PushRegistry
MIDlet-Vendor: Sun Microsystems
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0

Obrigado!!!!
Abraços

1 Resposta

duardor

Foi minha culpa!
:frowning:
Eu nao estava usando o emulator JAM…
Agora funciona de acordo…

Abraços

Criado 16 de fevereiro de 2004
Ultima resposta 16 de fev. de 2004
Respostas 1
Participantes 1