Total members 11895 |It is currently Thu Dec 12, 2024 12:48 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





:yahoo:




Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

Code:
package javaSMS;

import com.jacob.activeX.*;
import com.jacob.com.*;

public class javaSMSTest {
   //extract "return value" as boolean, integer and assign to these variables:-
   private static boolean bSMS;
   private static int iSMS;
   
   
   /**
    * @param args
    */
   public static void main(String[] args) {
      
      //construct an object -- "SMSAPIJava", a Java wrapper for SMS class in "MobitekSMSAPI5.dll"
      ActiveXComponent SMSAPIJava = new ActiveXComponent ("MobitekSMSAPI5.SMS");

//&&&&&&&&&& connect GSM modem to computer &&&&&&&&&&&&&&&&&&
      //call API to connect GSM modem to computer at COM port no. 2
      //the return value of the API call is assigned to "SMSAPIReturnValue"
      Variant SMSAPIReturnValue = SMSAPIJava.invoke("ModemInit", 2);
      //since the return value of function "ModemInit" is an integer, so extract the return value as an integer and assign to "iSMS"
      iSMS = SMSAPIReturnValue.getInt();
      switch iSMS)
      {
         case 0 : System.out.println("GSM modem is NOT connected to computer!"); return;
         case 1 : System.out.println("GSM modem is connected to computer."); break;
         case 2 : System.out.println("GSM modem is NOT connected to computer because a PIN is required!"); return;
         case 3 : System.out.println("GSM modem is NOT connected to computer because wrong PIN is entered!"); return;
         case 4 : System.out.println("GSM modem is NOT connected to computer because SIM card is blocked by network operator!"); return;
         case 5 : System.out.println("GSM modem is NOT connected to computer because SIM card has problem!"); return;
      }
//&&&&&&&&&& end: connect GSM modem to computer &&&&&&&&&&&&&&&&&&
      
//!!!!!!!!!! check connection between GSM modem and GSM network !!!!!!!!!!!!!!!!!!!!!!!!   
      //call API to check connection with GSM network, the return value of the API call is assigned to "SMSAPIReturnValue"
      SMSAPIReturnValue = SMSAPIJava.invoke("ConnectToGSM");
      //since the return value of "ConnectToGSM" is a boolean, so extract the return value as a boolean and assign to "bSMS"
      bSMS = SMSAPIReturnValue.getBoolean();
      if (bSMS)
      {
         System.out.println("GSM modem is connected to GSM network.");
      }   
      else
      {
         System.out.println("GSM modem is NOT connected to GSM network!");
      }
//!!!!!!!!!! end: check connection between GSM modem and GSM network !!!!!!!!!!!!!!!!!!!!!!!!
      
//~~~~~~~~~~~~~~~~ check signal strength of GSM network ~~~~~~~~~~~~~~~~~~~~~~~
      //call API to check signal strength of GSM network, the return value of the API call is assigned to "SMSAPIReturnValue"
      SMSAPIReturnValue = SMSAPIJava.invoke("GetSignalStrength");
      //since the return value of "GetSignalStrength" is an integer, so extract the return value as an integer and assign to "iSMS"
      iSMS = SMSAPIReturnValue.getInt();
      switch (iSMS)
      {
         case -1 : System.out.println("Unable to get signal strength!"); break;
         case 0 : System.out.println("NO signal strength!"); break;
         case 1 : System.out.println("WEAK signal strength."); break;
         case 2 : System.out.println("NORMAL signal strength."); break;
         case 3 : System.out.println("STRONG signal strength."); break;      
      }
//~~~~~~~~~~~~~~~~ end: check signal strength of GSM networki ~~~~~~~~~~~~~~~~~~~~~~~

//########### turn delivery status report on #######################
      //call API to turn delivery status report on
      //the return value of the API call is assigned to "SMSAPIReturnValue"
      SMSAPIReturnValue = SMSAPIJava.invoke("DeliveryReportOn");
      //since the return value of "DeliveryReportOn" is a boolean, so extract the return value as a boolean and assign to "bSMS"
      bSMS = SMSAPIReturnValue.getBoolean();
      if (bSMS)
      {
         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; "ToMessage" is the SMS to be send to the recipient
      SMSAPIJava.setProperty("ToNumber", "0163311600");
      SMSAPIJava.setProperty("ToMessage", "Hello from JAVA. Test DSR 6");
      //call API to send out SMS, the return value of the API call is assigned to "SMSAPIReturnValue"
      SMSAPIReturnValue = SMSAPIJava.invoke("SendSMS");
      //since the return value of "SendSMS" is a boolean, so extract the return value as a boolean and assign to "bSMS"
      bSMS = SMSAPIReturnValue.getBoolean();
      if (bSMS)
      {
         System.out.println("Messange sent!");
         
         //try 3 times
         for (int i=1; i<=3; i++)
         {
            //call API to get delivery status report, the return value of the API call is assigned to "SMSAPIReturnValue"         
            SMSAPIReturnValue = SMSAPIJava.invoke("GetDeliveryReport");
            //since the return value of "GetDeliveryStatusReport" is a boolean, so extract the return value as a boolean and assign to "bSMS"
            bSMS = SMSAPIReturnValue.getBoolean();
            
            if (bSMS)
            {
               //when "GetDeluveryStatusReport = True", then get value of properties
               int DRStatus = SMSAPIJava.getPropertyAsInt("DRStatus");                              
               String DRMNRecipient = SMSAPIJava.getPropertyAsString("DRMNRecipient");
               String DRMsgRef = SMSAPIJava.getPropertyAsString("DRMsgRef");
               String DRFDate = SMSAPIJava.getPropertyAsString("DRFDate");
               String DRFTime = SMSAPIJava.getPropertyAsString("DRFTime");
               String DRRDate = SMSAPIJava.getPropertyAsString("DRRDate");
               String DRRTime = SMSAPIJava.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!");
            }
            
         }
         
      }
      else
      {
         System.out.println("Messange NOT sent!");
      }
//------------------ end: send SMS ----------------------------------------
      
//+++++++++++++++++++++ read SMS ++++++++++++++++++++++++++
      //call API to read incoming SMS, the return value of the API call is assigned to "SMSAPIReturnValue"         
      SMSAPIReturnValue = SMSAPIJava.invoke("ReadSMS");
      //since the return value of "ReadSMS" is a boolean, so extract the return value as a boolean and assign to "bSMS"
      bSMS = SMSAPIReturnValue.getBoolean();
      //if there is new SMS, then get property
      if (bSMS)
      {
         //property "MN" is the sender's number         
         String InNumber = SMSAPIJava.getPropertyAsString("MN");
         //property "MSG" is the sender's message
         String InMessage = SMSAPIJava.getPropertyAsString("MSG");
         System.out.println("Number " + InNumber + ": " + InMessage );
      }
      else
      {
         System.out.println("No incoming SMS!");
      }
//+++++++++++++++++++++ end: read SMS ++++++++++++++++++++++++++      
      
      
//------- close connection between GSM modem and computer ---------------
      //call API to close connection between GSM modem and computer, the return value of the API call is assigned to "SMSAPIReturnValue"
      SMSAPIReturnValue = SMSAPIJava.invoke("ModemClose");
      //since the return value of "ModemClose" is a boolean, so extract the return value as a boolean and assign to "bSMS"
      bSMS = SMSAPIReturnValue.getBoolean();
      if (bSMS) System.out.println("Connection between GSM modem and computer is closed." );
      else System.out.println("Connection between GSM modem and computer CANNOT be closed!" );      
   }
//------- end: close connection between GSM modem and computer ---------------


Please found :
java/connecting-to-pc-from-mobile-using-bluetooth-in-java-t711.html

I found java code snippet to send and receive SMS .

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : sending sms using java code and bluetoth device pls send the
 i want code for connecting mobile and pc can u send me code     -  
 How to upload and retrieve image in jsp please send me code     -  
 please give me source code send, receive from mobile to pc     -  
 Java Applets used for send sms     -  
 Exception errror at LocalDevice device = LocalDevice.getLoc     -  
 sending sms from bluetooth mobile to pc     -  
 Help Sending e-mail from VB.Net application     -  
 Sending One lakh character in ajax     -  
 Sending a post request using AJAX     -  
 AJAX - Sending a request to a server     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com