SMS GATEWAY Text local
Android Studio Application - Send SMS using text local an SMS GATEWAY

Hi, Guys Welcome to Proto Coders Point.

This Article will learn how to develop an android application that can send SMS or bulk SMS to mobiles number.

In this  Aritcle, we are going to make use  https://textlocal.in/ to send SMS from our android app.

What is Textlocal?

India’s No. 1 Bulk SMS Platform Increase sales and customer satisfaction with smarter SMS campaigns, instant OTPs, notifications, two-way interactions & other award-winning bulk SMS services. this SMS sender android application can we used to send promotional SMS, bill SMS, and much more SMS services in India.

Flutter SMS send data to default sm...
Flutter SMS send data to default sms app - YouTube #shorts tutorial
What is SMS GATEWAY Services ?

An SMS Gateway enables a computer to send and receive SMS text messages to and from a SMS capable device over the global telecomunications network (normally to a mobile phone).

The SMS Gateway translates the message sent, and makes it compatible for delivery over the network to be able to reach the recipient.

Android App development to send SMS using text local an SMS GATEWAY || with source code

Android studio send sms to mobile number implementation video.

Developing an android application to send message to mobile number

So let’s begin implementation of android application development with TEXTLOCAL SMS GATEWAY SERVICES API.

Step by Step integration of android codes.

Textlocal Account 

  1. Creating a account in TextLocal.in
  2. Creating and getting a SMS API key in textlocal.

Android implementation Codes

  1. Creating a New Android Studio Project.
  2. Design a layout in main_activity.xml.
  3. writing java code in Main_Activity.java class.

Creating a account in TextLocal.in

To be able to send sms through textlocal.in SMS Gateway services you need to create an account under textlocal.in 

Creating an account in textlocal
Creating an account in textlocal
dashboard of textlocal sms gateway
dashboard of textlocal a sms gateway

Creating and getting a SMS API key in textlocal.

When you are in textlocal dashboard navigate Towards – > Settings -> API KEY.

Create a new SMS API key

creating a new SMS API KEY
creating a new SMS API KEY

You need to keep a note of the SMS API KEY you have generated just now, so that you can easily copy cost the sms api key in android studio project.

All set in textlocal website, we have now successfully created a account under textlocal and generated a API key.

Android Studio Implementation of SMS GATEWAY SERVICES

Complete project Source code is been listed down below, so that you can download the SMS sending project.

Now Let is  begin implementation the source code in android studio.

Creating a SMS sending project in android studio.

File -> New -> New Project ->select a empty activity

Design a layout in main_activity.xml.

Main_Activity.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SEND SMS"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.042" />

    <Button
        android:id="@+id/submit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="44dp"
        android:layout_marginBottom="420dp"
        android:text="Submit"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/editText2"
        app:layout_constraintVertical_bias="0.038" />

    <EditText
        android:id="@+id/number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="Number"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

    <EditText
        android:id="@+id/msg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="136dp"
        android:ems="10"
        android:gravity="start|top"
        android:hint="Message"
        android:inputType="textMultiLine"
        app:layout_constraintBottom_toTopOf="@+id/submit"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Above xml code has 2 EditText and a Button

EditText1 is with ID number and EditText2 is with ID msg, that holds respectively mobile number and sms message to be sent.

Button is with ID Submit that fetch text from editext and send data to SMS gateway through SMS API key,

Writing java code in Main_Activity.java class

Main_Activity.java

package protocoderspoint.com.smsapi;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class MainActivity extends AppCompatActivity {

    Button submit;
    EditText number,msg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        submit=(Button)findViewById(R.id.submit);
        number=(EditText)findViewById(R.id.number);
        msg=(EditText)findViewById(R.id.msg);


        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String phono = number.getText().toString();
                String msgtext = msg.getText().toString();

                try {
                    // Construct data
                    String apiKey = "apikey=" + "Replace with your API KEY";
                    String message = "&message=" + msgtext;
                    String sender = "&sender=" + "TXTLCL";
                    String numbers = "&numbers=" + phono;

                    // Send data
                    HttpURLConnection conn = (HttpURLConnection) new URL("https://api.textlocal.in/send/?").openConnection();
                    String data = apiKey + numbers + message + sender;
                    conn.setDoOutput(true);
                    conn.setRequestMethod("POST");
                    conn.setRequestProperty("Content-Length", Integer.toString(data.length()));
                    conn.getOutputStream().write(data.getBytes("UTF-8"));
                    final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                    final StringBuffer stringBuffer = new StringBuffer();
                    String line;
                    while ((line = rd.readLine()) != null) {
                        stringBuffer.append(line);

                        Toast.makeText(MainActivity.this,line,Toast.LENGTH_LONG).show();
                    }
                    rd.close();


                } catch (Exception e) {
                    System.out.println("Error SMS "+e);

                }
            }
        });

        StrictMode.ThreadPolicy st = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(st);
    }
}

In the above java class code we have four parameter that should be passed to textlocal gateway service.

  1. SMS API KEY.
  2. MESSAGE ( Fetched from EditText box ).
  3. SENDER ( It should be ‘TXTLCL’).
  4. Numbers ( Fetched from EditText box ).

Numbers can be seperated with commas (,) Eg: 875877XXX,548848xxx,66652xxx4454. So that we can send bulk sms at a time.

Conclusion :

In this Article, we have developled an android application that is capable to send bulk sms with some message like promotional sms, bill sms or any kind of message to your customer using SMS gateway service by Textlocal.

 

Comments are closed.