Posted By

Broadnet on 07/18/17


Tagged

code java api sample messaging sms


Versions (?)

Example of Java Sample SMS code


 / Published in: Java
 

URL: https://broadnet.me/developer-tools/sms-sample-code/java-sample-code-sms.html

This example of Java SMS Sample Code utilizes a clich├ęd Java Object API.

  1. //Android SMS API integration code
  2.  
  3. //Your application url
  4. String ApiUrl = "ApiUrl";
  5.  
  6. //Your User Id
  7. String user = "user";
  8.  
  9. //Your password
  10. String pass = "****";
  11.  
  12.  
  13. //Multiple mobiles numbers separated by comma
  14. String mobiles = "9999999";
  15. //Sender ID,While using route4 sender id should be 6 characters long.
  16. String sid = "102234";
  17. //Your message to send, Add URL encoding here.
  18. String message = "Test message";
  19.  
  20. URLConnection myURLConnection=null;
  21. URL myURL=null;
  22. BufferedReader reader=null;
  23.  
  24. //encoding message
  25. String encoded_message=URLEncoder.encode(message);
  26.  
  27. //Send SMS API
  28. String mainUrl="https://broadnet.mme/api/xxxx.php?";
  29.  
  30. //Prepare parameter string
  31. StringBuilder sbPostData= new StringBuilder(mainUrl);
  32. sbPostData.append("user="+user);
  33. sbPostData.append("&pass="+pass);
  34. sbPostData.append("&mobiles="+mobiles);
  35. sbPostData.append("&message="+encoded_message);
  36. sbPostData.append("&sid="+sid);
  37.  
  38. //final string
  39. mainUrl = sbPostData.toString();
  40. try
  41. {
  42. //prepare connection
  43. myURL = new URL(mainUrl);
  44. myURLConnection = myURL.openConnection();
  45. myURLConnection.connect();
  46. reader= new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
  47.  
  48. //reading response
  49. String response;
  50. while ((response = reader.readLine()) != null)
  51. //print response
  52. Log.d("RESPONSE", ""+response);
  53.  
  54. //finally close connection
  55. reader.close();
  56. }
  57. catch (IOException e)
  58. {
  59. e.printStackTrace();
  60. }

Report this snippet  

You need to login to post a comment.