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);
}
}
}