Wednesday, July 30, 2008

J2ME Mobile Code



How to send SMS using J2ME

package sms;

import javax.microedition.io.Connector;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;


/**
* The text field demo displays all of the text field types on the screen
* allowing the user to edit them at will.
*
* @version 2.0
*/
public class SMSDemo extends MIDlet implements CommandListener {
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
private Command sendCommand = new Command("Send", Command.SCREEN, 1);

private boolean firstTime;
private Form mainForm;
private TextField txtPhone = null;
private TextField txtMsg = null;

public SMSDemo() {
firstTime = true;
mainForm = new Form("SMS Demo");
}

protected void startApp() {
if (firstTime) {

mainForm.append(txtPhone = new TextField("Phone", "", 15, TextField.PHONENUMBER));
mainForm.append(txtMsg = new TextField("Message","",260, TextField.ANY));
mainForm.addCommand(sendCommand);
mainForm.addCommand(exitCommand);
mainForm.setCommandListener(this);
firstTime = false;
}

Display.getDisplay(this).setCurrent(mainForm);
}

public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
if (c == sendCommand) {
try
{
String addr = "sms://+91"+ txtPhone.getString() +":50000";
MessageConnection conn = (MessageConnection)Connector.open(addr);
TextMessage msg = (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(txtMsg.getString());
conn.send(msg);

Alert a = new Alert("Success", "Message Sent", null, AlertType.INFO);
Display.getDisplay(this).setCurrent(a);
}
catch(Exception ex)
{
Alert a = new Alert("Message not Sent", ex.getMessage(), null, AlertType.ERROR);
Display.getDisplay(this).setCurrent(a);
}
}
}

protected void destroyApp(boolean unconditional) {
}

protected void pauseApp() {
}
}


Output

China Mobile

China Mobile Secret Codes :
Default user code : 1122, 3344, 1234, 5678
Engineer mode : *#110*01#
Factory mode : *#987#
Enable COM port : *#110*01# -> Device -> Set UART -> PS Config -> UART1/115200
Restore factory settings : *#987*99#
LCD contrast : *#369#
Software version : *#800#
Software version : *#900#
Set default language : *#0000# Send
Set English language : *#0044# Send
Set English language (new firmware) : *#001# Send
Sefault user code : 1122, 3344, 1234, 5678

If anyone knows more china mobile codes, pls let me know.


Default Lock/Unlock SIM Pin for China Mobiles is 1234(mostly, be careful u will have only 3 chance to try if you don't know your pin).
Default Lock/Unlock Phone Pin for China Mobiles is 0000(zero,zero,zero,zero) (mostly, be careful u will have only 3 chance to try if you don't know your pin).
Default Password pin to Restore the factory Settings for China Mobiles is 0000 (zero,zero,zero,zero) mostly.
Here are some of the secret service codes for china mobiles.

default user code: 1122, 3344, 1234, 5678
Engineer mode: *#110*01#
Factory mode: *#987#
Enable COM port: *#110*01# -> Device -> Set UART -> PS Config -> UART1/115200
Restore factory settings: *#987*99#
LCD contrast: *#369#
software version: *#800#
software version: *#900#
set default language: *#0000# Send
set English language: *#0044# Send
set English language (new firmware): *#001# Send