Отправить Android-смс автоматически - PullRequest
0 голосов
/ 13 июня 2018

[Скриншот базы данных Firebase] [1]

[! [База данных firebase] [1]] [1]

Я новичок в android и firebase и занимаюсь вождениемшкольное приложение.Я должен успешно добавить информацию о клиенте в базу данных Firebase («имя», «телефон», «от даты» и «время»).Я хочу отправить смс-уведомление клиенту, например («срок действия вашей лицензии скоро истечет») с использованием «phone» и «date» из базы данных firebase.SMS должны быть отправлены в срок истечения (я имею в виду «todate» в базе данных Firebase).Здесь я прикрепил свой скриншот базы данных Firebase.Пожалуйста, дайте мне пример того, как это сделать.

Обновить данные клиента

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>

1 Ответ

0 голосов
/ 13 июня 2018

Вы можете начать с просмотра «Сервисов» и создать тот, который проверяет текущую дату (каждый день) и делает запрос из базы данных на любые записи с expiry_date == todays_date.

Учебник по услугам

Если это так, соберите номера телефонов в списке и обработайте их с помощью метода отправки SMS.

SMSОтправка

При тестировании функции SMS убедитесь, что вы запросили разрешение в файле манифеста, и, в зависимости от версии Android, запросите перед выполнением привилегии.

...