Android SmsManager send message to multiple recipient from sqlite database

how to send message in android programmatically
smsmanager.sendtextmessage not working
android code to send sms automatically
smsmanager not sending sms
sms intent android
android code to send sms via internet
android send sms in background
sending message in android studio java tutorial

I'm newbie to android please help me in my problem. I want to send message to multiple numbers. The numbers are saved in SQLite database. I want to send the message to all the numbers saved in database table.

Here's my code so far it only send sms to only one number in my database. It only send to the first number in my table.

private void sendSMS(String message) {
    if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
            != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS)
            != PackageManager.PERMISSION_GRANTED){
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.SEND_SMS},
                MY_PERMISSION_REQUEST_SEND_SMS);
    }else{
        SmsManager sms = SmsManager.getDefault();
        SQLiteDatabase db = myDB.getWritableDatabase();
        Cursor res = db.rawQuery("select * from recipients_tbl", null);
        if(res != null && res.moveToFirst()) {
            String num = res.getString(1);
            sms.sendTextMessage(num, null, message, sentPI, deliveredPI);
        }
    }
}

The reason it is only sending it to the first number is you are not looping trough your result. In order for it to work you will need to write your code like this:

if(res != null){
    for(res.moveToFirst(); !res.isAfterLast(); res.moveToNext())
    {
        String num = res.getString(1);
        sms.sendTextMessage(num, null, message, sentPI, deliveredPI);
    }
}

This is typically used for devices that support multiple active subscriptions at once​. Whether multipart SMS should be sent as separate messages. getDefault () Get the default instance of the SmsManager. void. sendDataMessage ( String destinationAddress, String scAddress, short destinationPort, byte [] data, PendingIntent sentIntent, PendingIntent deliveryIntent) Send a data based SMS to a specific application port. void.


First thing first, change:

SQLiteDatabase db = myDB.getWritableDatabase();

to:

SQLiteDatabase db = myDB.getReadableDatabase();

Because you are not writing to database.

Then, what you have to do is, iterate through each and every row:

while(res.moveToNext())
{
    String num = res.getString(1);
    sms.sendTextMessage(num, null, message, sentPI, deliveredPI);
}
res.close();

You know, Cursor is pointing at the first row and you have to get that cursor to next row by moveToNext(). And lastly donot forget to close the Cursor.

FYK: What's the best way to iterate an Android Cursor?

For Android specific development please see the Android forum; Updated: 18 May 2020. message.trim().length()>0) { SmsManager sms = SmsManager. In this application, we will learn how to send Sms without getting any sending report. So create your new project and drop one button to XML file which will use to send Sms. Here we gave a simple example, you all can take mobile number and text message from edit text and send to particular user. The code of android XML file is given below:


Android - Sending SMS - In Android, you can use SmsManager API or devices In this tutorial, we shows you two basic examples to send SMS message. Android - Spelling Checker · Android - SQLite Database · Android - Support Library to use Intent object to launch SMS client to send an SMS to the given recipients. Even for Intent, it required a SEND_SMS permission in our android manifest to send SMS. Following is the code snippet to set SEND_SMS permissions in manifest file. <uses-permission android:name="android.permission.SEND_SMS"/>. Now we will see how to send SMS in android application using SMSManager API with examples.


sendTextMessage(MobileNumber,null,Message,null,null);. SMSManager API required SEND_SMS permission in our android manifest to send SMS. Following​  In Android, you can use SmsManager API or devices Built-in SMS application to send SMS's. In this tutorial, we shows you two basic examples to send SMS message − SmsManager API. SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("phoneNo", null, "sms message", null, null); Built-in SMS application


If you want all of the recipients to be able to chat together, you can add up to 256 May 14, 2019 · Send Message to Specific number on WhatsApp Android Posted On Yet you have to edit the text before sending it to multiple contacts. App which allows small 15 Mar 2012 java – Activity to send SMS via SmsManager . This class was deprecated in API level 4. Replaced by android.telephony.SmsManager that supports both GSM and CDMA. Class Overview. Manages SMS operations such as sending data, text, and pdu SMS messages.


Sending Message to Multiple Numbers using Intent - android. You can send SMS silently using SMSManager. as following : try { String ph="1234568790";  We can send sms in android via intent. You need to write only 4 lines of code the send sms in android. Drag the 2 edittexts, 2 textviews and 1 button from the pallete, now the activity_main.xml file will like this: Let's write the code to make the phone call via intent.