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
“);
}
}
Explaination:
- You must implement SMSListener
- you must override method receivedSMS
- you must add your class as listener with this code : addSMSListener
- then every incoming sms will invoke receivedSMS method from your class
- go rock men…..
Recent Comments