This J2ME tip demostrates a method of sending binary messages such as PNG images, sound files etc. In the program BinaryMessage interface represents a binary message. The setPayloadData() method sets the value of the payload in the data container without checking whether the value is valid or not.

void sendSMS(byte data[]) {

    try {
        
        String destAddress = "sms://9590528892:5001";
        
        MessageConnection smsConnection =
                (MessageConnection)Connector.open(destAddress);
        
        //Create binary message
        BinaryMessage binaryMSG = (BinaryMessage)smsConnection.newMessage(
                MessageConnection.BINARY_MESSAGE);
        
        //Setting destination add
        binaryMSG.setAddress(destAddress);
        
        //Add payload data
        binaryMSG.setPayloadData(data);
        
        //Now send the message
        smsConnection.send(binaryMSG);
        smsConnection.close();
        
    } catch(Exception e) {
        
        System.out.println("e="+e);
        frm.append("e="+e);        
    }
}

 


 

 

 Related Tips