How to send SMS in java using SMS Gateways App

Using the SMS garways app (https://play.google.com/store/apps/details?id=eu.apksoft.android.smsgateway&hl=en)

Port of app:

IP address of your phone currently connected to a network.

<pre class=”code”>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

public class SendSMS {
public static void send(String mobileNumber, String textMessage, String ipAddress,
int portNumber) {
try {
String urlString = “http://” + ipAddress + “:” + portNumber
+ “/sendsms?phone=” + mobileNumber + “&text=” +URLEncoder.encode(textMessage,”ISO-8859-1″);
URL url = new URL(urlString);
URLConnection urlConnection = url.openConnection();
HttpURLConnection connection = null;
if (urlConnection instanceof HttpURLConnection) {
connection = (HttpURLConnection) urlConnection;
} else {
System.out.println(“INVALID SMS HTTP URL.”);
return;
}
BufferedReader in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String urlString2 = “”;
String current;
while ((current = in.readLine()) != null) {
urlString += current;
}
System.out.println(urlString2);
}catch(MalformedURLException e){
System.out.println(“Please provide valid IP and PORT :”+e.getMessage());
}
catch (IOException e) {
System.out.println(“Invalid phone number!!”);
}
}
}

</pre>
you can send SMS with NO limit of chars (160)

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Enable Notifications OK No thanks