Java Sample Code for MOBITEK STK API version 6.3 — Send and Read SMS

Introduction

STK refers to SIM Tookit or SIM Tool Kit.

SAT refers to SIM Application Toolkit

Both terms are interchangeable.

Java Sample Code

Declaring variables

 static Variant vMOBITEK;
 static boolean bMOBITEK;
 static int iMOBITEK;
 static String sMOBITEK;

//construct objects for each class in "MobitekSTK6.dll"

static ActiveXComponent Modem = new ActiveXComponent ("MobitekSTK6.Modem");
static ActiveXComponent STKAPI = new ActiveXComponent ("MobitekSTK6.SIMToolKit");
static ActiveXComponent SMS = new ActiveXComponent ("MobitekSTK6.SMS");

To send SMS in java

public static void sendMessage()
 //SV: to send SMS; maximum 160 characters 
 {

 //########### turn delivery status report on #######################
 //call API to turn delivery status report on
 vMOBITEK = SMS.invoke("DeliveryReportOn");
 //the return value of "DeliveryReportOn" is a boolean
 bMOBITEK = vMOBITEK.getBoolean();
 //AQ : therefore assign bMOBITEK as return value of "DeliveryReportOn" 
 if (bMOBITEK)
 {
 System.out.println("Delivery status report is turned on.");
 }
 else
 {
 System.out.println("Delivery status report is NOT turned on!");
 }
 //########### end: turn delivery status report on #######################
 
 //------------------ send SMS ----------------------------------------
 //set value of property;
 //"ToNumber" is the recipient's number;
 SMS.setProperty("ToNumber", "0176096718");
 //"ToMessage" is the SMS to be send to the recipient; maximum 160 characters
 SMS.setProperty("ToMessage", "Hello from JAVA with SMS API version 7. Test no. 6");
 //AQ : call API to send new message
 vMOBITEK = SMS.invoke("SendSMS");
 //AQ : the return value of "SendSMS" is a boolean
 bMOBITEK = vMOBITEK.getBoolean();
 //AQ : therefore assign bMOBITEK as return value of "SendSMS" 
 if (bMOBITEK)
 {
 System.out.println("Message sent!");
 
 //try 3 times
 for (int i=1; i<=3; i++) 
 {
 try {
 //AQ : call API to get delivery report
 vMOBITEK = SMS.invoke("GetDeliveryReport");
 //AQ : the return value of "GetDeliveryReport" is a boolean
 //AQ : therefore assign bMOBITEK as return value of "GetDeliveryReport"
 bMOBITEK = vMOBITEK.getBoolean();
 if (bMOBITEK)
 {
 //when "GetDelIveryStatusReport = True", then get value of properties
 int DRStatus = SMS.getPropertyAsInt("DRStatus"); 
 String DRMNRecipient = SMS.getPropertyAsString("DRMNRecipient");
 String DRMsgRef = SMS.getPropertyAsString("DRMsgRef");
 String DRFDate = SMS.getPropertyAsString("DRFDate");
 String DRFTime = SMS.getPropertyAsString("DRFTime");
 String DRRDate = SMS.getPropertyAsString("DRRDate");
 String DRRTime = SMS.getPropertyAsString("DRRTime");
 
 if (DRStatus == 1)
 {
 //System.out.println("The status of your outgoing SMS with reference number, " + DRMsgRef + ", is " + DRStatus + ".");
 System.out.println("The status of your outgoing SMS with reference number, " + DRMsgRef + ", is delivered.");
 System.out.println("Your outgoing SMS was received by the SMS Centre on " + DRRDate + ", at " + DRRTime + ", and was successfully delivered to " + DRMNRecipient + ", on " + DRFDate + ", at " + DRFTime + ".");
 }
 else
 if (DRStatus == 0)
 {
 //System.out.println("The status of your outgoing SMS with reference number, " + DRMsgRef + ", is " + DRStatus + ".");
 System.out.println("The status of your outgoing SMS with reference number, " + DRMsgRef + ", is not delivered.");
 System.out.println("Your outgoing SMS was received by the SMS Centre on " + DRRDate + ", at " + DRRTime + ", and was NOT successfully delivered to " + DRMNRecipient + "."); 
 }
 else
 if (DRStatus == 2)
 {
 //System.out.println("The status of your outgoing SMS with reference number, " + DRMsgRef + ", is " + DRStatus + ".");
 System.out.println("The status of your outgoing SMS with reference number, " + DRMsgRef + ", is unknown.");
 System.out.println("Your outgoing SMS was received by the SMS Centre on " + DRRDate + ", at " + DRRTime + ", and NO status is available.");
 }
 
 break; 
 
 }
 
 else
 {
 System.out.println("No delivery status report available!"); 
 }
 
 //SV: wait for 5 seconds before looping; delivery report from GSM network takes time
 Thread.sleep(5000);
 }
 catch (InterruptedException e)
 {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 } 
 }
 else
 {
 System.out.println("Message NOT sent!");
 }
 //------------------ end: send SMS ----------------------------------------
 }

To Read SMS in java

public static void readMessage() {
 //AQ : readMessage() function is for modem to read incoming message from the sender 
 //------------------------------------------- read SMS -------------------------------------------
 //call API to read incoming SMS 
 vMOBITEK = SMS.invoke("ReadSMS");
 //AQ : the return value of "ReadSMS" is a boolean, therefore assign bMOBITEK as return value of "ReadSMS"
 bMOBITEK = vMOBITEK.getBoolean();
 //if there is new SMS, then get property
 if (bMOBITEK)
 {
 //property "MN" is the sender's mobile number 
 String InNumber = SMS.getPropertyAsString("MN");
 //property "MSG" is the sender's message
 String InMessage = SMS.getPropertyAsString("MSG");
 //property "SCTS" time of the message received by SMS Centre
 String InTime = SMS.getPropertyAsString("SCTS");
 System.out.println("Incoming SMS Read \n From: " + InNumber + "\n Message: "+ InMessage + "\n Time: " + InTime );
 }
 else
 {
 System.out.println("No incoming SMS!");
 }
 //---------------------------------------- end: read SMS ----------------------------------------- 
 }

More Information

Path/File Access Error

Problem

When running sample code of Java for MOBITEK®  Q24 STK API, you may encounter an error message:-

Exception in thread “main” com.jacob.com.ComFailException: Invoke of: Init Source: MobitekSTK6 Description: Path/File access error

Applies To

  • MOBITEK®  Q24 STK API version 6.x
  • Windows 7 and above; 32 bit and 64 bit
  • JACOB version 1.14.3
  • JRE 1.6 and above

Solution

Run Eclipse as an administrator.

How Do You Locate a SIM Card in MOBITEK Q24 STK Modem Hub?

Multiple SIM Cards

Multiple SIM Cards

When you have a lot of SIM cards in different units of MOBITEK®  Q24 STK Modem Hub

MOBITEK Q24 STK Modem Hub_STKMH-US401-C_Front_2560 x 1920MOBITEK® Q24 STK Modem Hub

you will need to locate a particular SIM card after you have swap A card into different SIM slot MOBITEK®  Q24 STK Modem Hub.

MOBITEK®  Q24 STK API has a function that is able to locate the SIM card. By using Modem.GetIMSI()

What is IMSI?

International Mobile Subscriber Identity, it is a unique 15 digits of the SIM card. If you change SIM card to another slot, you can query the IMSI to find out where is the SIM card located. Refer to https://en.wikipedia.org/wiki/International_mobile_subscriber_identity

More Information

 

Posted in STK

Java Sample Code for MOBITEK STK API version 6.2 — InputRequest() and InputSubmit()

Introduction

STK refers to SIM Tookit.

SAT refers to SIM Application Toolkit

Both terms are interchangeable.

Java Sample Code

//To display a request from STK menu for an input
vMOBITEK = STKAPI.invoke("InputRequest");
sMOBITEK = vMOBITEK.getString();
System.out.println ("STK Menu has requested for an input: " + sMOBITEK + ".");
//To submit an input to STK Menu
strInput = "OK"
vMOBITEK = STKAPI.invoke("InputSubmit",strInput);
bMOBITEK = vMOBITEK.getBoolean();

More Information

MOBITEK Air-Time Reload Development Kit

MOBITEK Air-Time Reload Development Kit is for software developer to build an air-time reload or top-up system.

Air-Time is also known as pre-paid account. In mobile industry, pre-paid account holder needs to buy or top-up air-time in order to keep their account active. The buying of air-time is a top-up or reload transaction.

With any purchase of the MOBITEK®  Q24 STK Modem or MOBITEK®  Q24 STK Modem Hub, it comes with free AIR-TIME RELOAD DEVELOPMENT KIT. The kit contains the following:-

  1. MOBITEK® STK API version 6

    • refer to -- "MOBITEK_STK_API_version 6_Manual.pdf" for more information
    • New function is:-
      • USSD.USSDListen()
        This function call will listen for USSD prompt from the network operator and capture it. While listening, no other functions are allowed to be called, it will stop upon time-out (default is 3 seconds). If USSDListen() is not called, any USSD prompt is sent by network operator, then it will not be captured. If USSDListen() is called after USSD prompt is sent by network operator, then it will not be captured.
        This allow software developer to wait for a response or prompt from GSM network operator that is transmitted via USSD.
  2. MOBITEK® STK Engine (new)
    • MOBITEK® STK ENGINE is a software or application that will automate the process of selecting the menu item in the SIM Application Toolkit (STK). It is especially develeped for the air-time reload process. The menu selection process is script/text based, in other words, no coding is needed.
    • view video demonstration on editing the script …
    • view video demonstration on engine executing the script …
  3. Mobile Apps (Native) — Reload Menu for Nokia Smartphones

    • Python source code included
  4. Mobile Web — Reload Menu
    • Mobile xhtml source code included

More Information

  1. MOBITEK STK API
  2. MOBITEK Q24 STK MODEM
  3. MOBITEK Q24 STK MODEM HUB
Posted in STK