Posted by: didiksoft | October 28, 2009

Build SMS Gateway using mySMSlib

Building SMS Gateway using DidikSMSLib

This was example:

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package com.didik.test;

import com.didik.sms.SMSEngine;

import com.didik.sms.model.SMSEntity;

import com.didik.sms.model.SMSListener;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.logging.Level;

import java.util.logging.Logger;

/**

*

* @author Didik Rawandi

*/

public class Test implements SMSListener{

private SMSEngine sms;

public Test(){

try {

sms = new SMSEngine();

sms.ConnectPort(“COM3″);

sms.AddSMSListener(this);

sms.SendATCommand(“AT+CMGF=0″);

sms.SendATCommand(“AT+CSCS=\”GSM\”");

sms.SendATCommand(“AT+CNMI=2,1,2,0,0″);

sms.SendATCommand(“AT+CPMS=\”ME\”");

sms.SendATCommand(“AT+CMGL=0″);

} catch (Exception ex) {

ex.printStackTrace();

}

}

@Override

public void receiveSMS(SMSEntity smsEntity,String description) {

System.out.println(“Receive “+description);

process(smsEntity);

}

public static void main(String[] args){

new Test();

while(true);

}

private void process(SMSEntity smsEntity){

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);

System.out.println(smsEntity.getFrom() + “:” + smsEntity.getMsg() + “:” + sdf.format(Calendar.getInstance().getTime()));

sms.SendSMS(smsEntity.getFrom(), smsEntity.getMsg() + ” juga :D “);

}

}

Explaination:

  1. You must implement SMSListener
  2. you must override method receivedSMS
  3. you must add your class as listener  with this code : addSMSListener
  4. then every incoming sms will invoke receivedSMS method from your class
  5. go rock men…..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.