'send sms automatically using firebase database given phone number and date

Firebase database screenshot

enter image description here

I'm a beginner at android and firebase and am developing a driving school app. I am to successfully add customer details to a firebase database ('name', 'phone', 'fromdate' and 'todate'). I want to send an sms alert to the customer e.g. ("your licence is expiry soon.") using 'phone' and 'date' from the firebase database. The sms should be sent 7 days before the expiry date (I mean 'todate' in the firebase database). Here I've attached my firebase database screenshot. Please give me an example of how to do this.

Update customer details

public class Updatecustomer extends AppCompatActivity {


private EditText edtname, edtpho;
private Button btnsubmit;
private EditText datepickerto, datepickerfr;
private Calendar mcurrentDate, mlateDate;

int day, month, year;

private DatabaseReference childref;
private DatabaseReference listref;
private DatabaseReference noderef;

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

    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);


    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle("Update your Customer Details");

    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);


    datepickerto = (EditText)findViewById(R.id.datepickerto);
    datepickerfr = (EditText)findViewById(R.id.datepickerfr);

    edtname = (EditText)findViewById(R.id.edtname);
    edtpho = (EditText)findViewById(R.id.edtpho);

    btnsubmit = (Button)findViewById(R.id.btnsubmit);


    mcurrentDate = Calendar.getInstance();

    day = mcurrentDate.get(Calendar.DAY_OF_MONTH);
    month = mcurrentDate.get(Calendar.MONTH);
    year = mcurrentDate.get(Calendar.YEAR);

    day = day+1;

    datepickerto.setText(day+"-"+month+"-"+year);

    datepickerto.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            DatePickerDialog datePickerDialog = new 
  DatePickerDialog(Updateproduction.this, new 
  DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int 
  monthOfYear, int dayOfMonth) {
                    monthOfYear =monthOfYear+1;
                    datepickerto.setText(dayOfMonth+"-"+monthOfYear+"- 
  "+year);
                }
            }, year, month, day);
            datePickerDialog.show();
        }
     });

    mlateDate = Calendar.getInstance();

    day = mlateDate.get(Calendar.DAY_OF_MONTH);
    month = mlateDate.get(Calendar.MONTH);
    year = mlateDate.get(Calendar.YEAR);

    month = month+1;

    datepickerfr.setText(day+"-"+month+"-"+year);

    datepickerfr.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            DatePickerDialog datePickerDialog = new 
  DatePickerDialog(Updatecustomer.this, new 
  DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int 
  monthOfYear, int dayOfMonth) {
                    monthOfYear =monthOfYear+1;
                    datepickerfr.setText(dayOfMonth+"-"+monthOfYear+"- 
  "+year);
                }
            }, year, month, day);
            datePickerDialog.show();
        }
    });


    final FirebaseDatabase database = FirebaseDatabase.getInstance();
    final DatabaseReference table_user = database.getReference();

    childref = table_user.child("Rajadriving");


    btnsubmit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           final ProgressDialog mDiaglog = new 
  ProgressDialog(Updateproduction.this);
           mDiaglog.setMessage("Please Waiting...");
           mDiaglog.show();

            table_user.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {

    //if(dataSnapshot.child(spinnershift.getSelectedItem()
   .toString()).exists())
                    //  {
                    //     mDiaglog.dismiss();
                    //    Toast.makeText(Updatecustomer.this, "Data 
 already Stored", Toast.LENGTH_SHORT).show();
                    // }
                    //  else
                    {
                        mDiaglog.dismiss();
                        Datastore user = new 


  Datastore(datepickerfr.getText().toString(),datepickerto.getText()
 .toString(),
                                edtpho.getText().toString().trim(), 
  edtname.getText().toString().trim());


                        listref = 
 childref.child(datepickerfr.getText().toString());
                        noderef =  
 listref.child(edtname.getText().toString());
                        noderef.setValue(user);

                        //Intent addintent = new 
Intent(MainActivity.this,Paid.class);
                        // startActivity(addintent);
                        Toast.makeText(Updatecustomer.this, "Data saved 
successfully !", Toast.LENGTH_SHORT).show();
                        finish();
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });
        }
    });


 }


 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == android.R.id.home){
        this.finish();
    }
    return super.onOptionsItemSelected(item);
 }
 }

activity_update_customer.xml

<RelativeLayout 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="com.udayaj.rajadriving.Updatecustomer">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Raja Driving School"
    android:textStyle="bold"
    android:textColor="#f05"
    android:textSize="25dp"
    android:fontFamily="sans-serif"
    android:gravity="center"
    android:id="@+id/textView" />

<EditText
    android:id="@+id/edtname"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/datepickerfr"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="35dp"
    android:hint="Enter Customer Name"
    android:inputType="textPersonName"
    android:textSize="16dp" />

<EditText
    android:id="@+id/edtpho"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/edtname"
    android:layout_below="@+id/edtname"
    android:layout_marginTop="19dp"
    android:hint="Enter Phone No."
    android:inputType="number"
    android:minLines="10"/>


<Button
    android:id="@+id/btnsubmit"
    android:layout_width="150dp"
    android:layout_height="55dp"
    android:layout_below="@+id/edtpho"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="96dp"
    android:background="@drawable/sty_submit"
    android:text="Submit"
    android:textColor="@android:color/white" />

<EditText
    android:id="@+id/datepickerfr"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView5"
    android:layout_marginEnd="19dp"
    android:layout_toStartOf="@+id/datepickerto"
    android:hint="Enter From Date"
    android:inputType="date" />

<EditText
    android:id="@+id/datepickerto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_below="@+id/textView5"
    android:layout_marginEnd="42dp"
    android:hint="Enter Expire Date"
    android:inputType="date" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="23dp"
    android:text="Date use this format eg:6-6-2018."
    android:id="@+id/textView5" />

 </RelativeLayout>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source