Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
This page was last modified 12:47, 8 June 2008.

Como criar um alarme de aniversário no Java ME

From Forum Nokia Wiki

Artigo Original em: How to create birthday alarm in Java ME


Se você tem o mesmo problema que eu e sempre esquece o aniversário de seus amigos e familiares aqui está a solução.

Primeiro salve o nome do seu amigo, número do celular e a data de aniversário na lista de contatos. Depois disso usando a PIN API criamos a função.

void contactlist(){
 
PIM pim = PIM.getInstance();
ContactList contactList = null;
 
try {
contactList =
(ContactList)pim.openPIMList(PIM.CONTACT_LIST,PIM.READ_WRITE );
Enumeration en;
en = contactList.items();
Contact contact;
while(en.hasMoreElements())
{
contact = (Contact)en.nextElement();
…
}
catch( PIMException pimEx ){
// no contact list available!
System.out.println("EX - No contact list available.");
}
catch( SecurityException securityEx){
// the application is not allowed to access the list
System.out.println("EX - Access denied.");
}
}


Criamos uma outra função para enviar uma mensagem (SMS).


public void sendSms(){
    
    String message="happy birthday"+name;
    boolean result = true;
    try {
      //sets address to send message
      String addr = "sms://"+number;
      // opens connection
      MessageConnection conn = (MessageConnection) Connector.open(addr);
      // prepares text message
      TextMessage msg =
      (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
      //set text
      msg.setPayloadText(message);
      // send message
      conn.send(msg);
      conn.close();
      } catch (Exception e) {
        result = false;
      }
      return result;
  }
}


E para executar o MIDlet todos os dias usamos o alarme.


import	javax.microedtion.io.PushRegistry;
...
 
String connURL = "sms://";
String MIDletStr = "name_of_the_midlet";
String	FilterStr = "*";
 
try {
	PushRegistry.registerConnection(connURL,
		MIDletStr, FilterStr);
} catch ( ClassNotFoundException cnf ) {
	...
} catch ( IOException ioe ) {
	...
}
...
 
import	javax.microedtion.io.PushRegistry;
...
long	prevalarm;
String	MIDletname = "AlarmMIDlet";
Date	nexttime   = new java.util.Date() + 60000*60*24;
 
prevalarm = PushRegistry.registerAlarm( MIDletname, nexttime );
...

Crie uma MIDlet que vai executar com ajuda do alarme. Essa MIDlet compara a data corrente com o da lista do PIN.

Se existe algum item selecionado, ele associa o nome do amigo com o nome da variável e chama o método "sendsms()" que enviará uma mensagem para os amigos selecionados e também mostrará um alerta dizendo que uma mensagem foi enviada para o amigo xyz no seu aniversário.

Related Discussions
Thread Thread Starter Forum Replies Last Post
Creating Menu's for 9210 grantgowdy Symbian User Interface 1 2002-05-22 14:44
Java Verified leefisher Mobile Java General 12 2006-01-23 17:12
any api supplied by Symbian to use in midlet ? Nokia_Archive Symbian Tools & SDKs 3 2003-06-13 08:44
nokia 6260 java question rupske Mobile Java General 5 2007-01-29 05:30
launching WAP from a Java app? stevo999999 Mobile Java General 6 2006-03-30 01:02
 
Powered by MediaWiki
RDF Facets: qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX