title: Sent Message to Multiple number from firebase database in android
body: <p>I want to send message to multiple contacts from mobile.Flow is that Iam creating a Blood Bank application in which when user request a blood I show him the list of all user with matched blood group in firebase recycler view.In recycler,Iam showing him the name of user with 2 icon of call and message on click on any icon required process is working fine.
  What I want is when user request blood after showing him the list of matched blood group person I should pragmatically send message to all users those are shown in the list of matched blood group.
  I have viewed multiple question and and tried there answers but didn't get success to achieve it.</p>
  
  <p>In this I have tried another solution from stack overflow but the result is same it didn't send message</p>
  
  <pre><code>  private RecyclerView recyclerView;
      private DatabaseReference reference;
      String bloodGroup;
      LinearLayout linearLayout;
      ProgressDialog progressDialog;
      FirebaseRecyclerOptions&lt;Profiles&gt; model;
      FirebaseRecyclerAdapter&lt;Profiles, DonarViewHolder&gt; adapter;
      ArrayList&lt;String&gt; contactNumber = new ArrayList&lt;&gt;();
      HashSet&lt;String&gt; numbersSet = new HashSet&lt;&gt;();
  
      int MY_PERMISSIONS_REQUEST_SEND_SMS = 1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_donar_list);
          getView();
          showRecyclerView();
          sendMsg();
          contactNumber.addAll(numbersSet);
  
      }
  
      private void sendMsg() {
          for (int i = 0; i &lt; contactNumber.size(); i++)
          {
              String message = "Blood Required Urgently";
              String tempMobileNumber = contactNumber.get(i).toString();
              MultipleSMS(tempMobileNumber, message);
          }
      }
  
      private void MultipleSMS(String phoneNumber , String message) {
          String SENT = "SMS_SENT";
          String DELIVERED = "SMS_DELIVERED";
  
          PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
                  SENT), 0);
  
          PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
                  new Intent(DELIVERED), 0);
  
          // ---when the SMS has been sent---
          registerReceiver(new BroadcastReceiver() {
              @Override
              public void onReceive(Context arg0, Intent arg1) {
                  switch (getResultCode()) {
                      case Activity.RESULT_OK:
                          ContentValues values = new ContentValues();
                          for (int i = 0; i &lt; contactNumber.size() - 1; i++) {
                              values.put("address", contactNumber.get(i).toString());
                              // txtPhoneNo.getText().toString());
                              values.put("body", "Blood Required Urgently");
                          }
                          getContentResolver().insert(
                                  Uri.parse("content://sms/sent"), values);
                          Toast.makeText(DonarList.this, "SMS sent",
                                  Toast.LENGTH_SHORT).show();
                          break;
                      case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                          Toast.makeText(DonarList.this, "Generic failure",
                                  Toast.LENGTH_SHORT).show();
                          break;
                      case SmsManager.RESULT_ERROR_NO_SERVICE:
                          Toast.makeText(DonarList.this, "No service",
                                  Toast.LENGTH_SHORT).show();
                          break;
                      case SmsManager.RESULT_ERROR_NULL_PDU:
                          Toast.makeText(DonarList.this, "Null PDU",
                                  Toast.LENGTH_SHORT).show();
                          break;
                      case SmsManager.RESULT_ERROR_RADIO_OFF:
                          Toast.makeText(DonarList.this, "Radio off",
                                  Toast.LENGTH_SHORT).show();
                          break;
                  }
              }
          }, new IntentFilter(SENT));
  
          // ---when the SMS has been delivered---
          registerReceiver(new BroadcastReceiver() {
              @Override
              public void onReceive(Context arg0, Intent arg1) {
                  switch (getResultCode()) {
                      case Activity.RESULT_OK:
                          Toast.makeText(DonarList.this, "SMS delivered",
                                  Toast.LENGTH_SHORT).show();
                          break;
                      case Activity.RESULT_CANCELED:
                          Toast.makeText(DonarList.this, "SMS not delivered",
                                  Toast.LENGTH_SHORT).show();
                          break;
                  }
              }
          }, new IntentFilter(DELIVERED));
  
          SmsManager sms = SmsManager.getDefault();
          sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
      }
  
      private void showRecyclerView() {
          adapter = new FirebaseRecyclerAdapter&lt;Profiles, DonarViewHolder&gt;(model) {
              @Override
              protected void onBindViewHolder(@NonNull DonarViewHolder holder, int position, @NonNull Profiles profiles) {
                  String check = profiles.getBloodBank();
                  String number = profiles.getMobile_number();
                  numbersSet.add(profiles.getMobile_number());
                  System.out.println("all" + numbersSet);
                  ArrayList&lt;String&gt; bloodGroupMatched = new ArrayList&lt;&gt;();
                  bloodGroupMatched.addAll(profiles.getMatched_bloodGroups());
                  System.out.println("check" + bloodGroupMatched);
  
                  if (bloodGroupMatched.contains(bloodGroup)) {
                      holder.name.setText(profiles.getName());
                      holder.itemView.setVisibility(View.VISIBLE);
                      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                      params.setMargins(10, 5, 5, 10);
                      holder.itemView.setLayoutParams(params);
                  } else {
  
                      holder.itemView.setVisibility(View.GONE);
                      holder.itemView.setLayoutParams(new RecyclerView.LayoutParams(0, 0));
                  }
                  holder.call.setOnClickListener(v -&gt; {
                      boolean conditionCheck = true;
                      Intent callIntent = new Intent(Intent.ACTION_DIAL);
                      callIntent.setData(Uri.parse("tel:" + number));
  
                      if (ActivityCompat.checkSelfPermission(DonarList.this,
                              Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                          ActivityCompat.requestPermissions(DonarList.this,
                                  new String[]{Manifest.permission.CALL_PHONE}, 1);
  
                      }
                      startActivity(callIntent);
  
                  });
                  holder.msg.setOnClickListener(v -&gt; {
  
                      Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
                      smsIntent.setType("vnd.android-dir/mms-sms");
                      smsIntent.setData(Uri.parse("sms:" + number));
                      if (ActivityCompat.checkSelfPermission(DonarList.this,
                              Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED) {
                          ActivityCompat.requestPermissions(DonarList.this,
                                  new String[]{Manifest.permission.SEND_SMS}, MY_PERMISSIONS_REQUEST_SEND_SMS);
                      } else {
                          startActivity(smsIntent);
                      }
                  });
              }
  
              @NonNull
              @Override
              public DonarViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                  View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_donar_view_holder, parent, false);
                  return new DonarViewHolder(view);
              }
          };
          recyclerView.setLayoutManager(new LinearLayoutManager(this));
          adapter.startListening();
          progressDialog.dismiss();
          recyclerView.setAdapter(adapter);
      }
  
      private void getView() {
          progressDialog = HelperClass.showProgressDialog(this, "Loading..");
          if (getIntent() != null &amp;&amp; getIntent().hasExtra("bloodGroup")) {
              bloodGroup = getIntent().getStringExtra("bloodGroup");
              Toast.makeText(this, bloodGroup, Toast.LENGTH_SHORT).show();
          }
          recyclerView = findViewById(R.id.donar_list_recycler);
          linearLayout = findViewById(R.id.recylerLayout);
          reference = FirebaseDatabase.getInstance().getReference().child(Constants.content).child(Constants.profiles);
  
          model = new FirebaseRecyclerOptions.Builder&lt;Profiles&gt;()
                  .setQuery(reference, Profiles.class).build();
  
      }
  
      @Override
      public void onStart() {
          super.onStart();
          if (adapter != null) {
              adapter.startListening();
          }
      }
  
  
      @Override
      public void onStop() {
          super.onStop();
          if (adapter != null) {
              adapter.stopListening();
          }
      }
  
      @Override
      protected void onResume() {
          super.onResume();
          if (adapter != null) {
              adapter.startListening();
          }
      }
  }
  </code></pre>
  
  <p>Note : Iam trying to send message to multiple users not a single user</p>