android - Send SMS to each contact in SQLite Database -
i have sqlite table has different phone numbers , different messages each. want id each row intentservice can send unique sms each number. have done:
public class notificationservice extends intentservice { public notificationservice() { super(notificationservice.class.getsimplename()); } @override public void oncreate() { super.oncreate(); } @override protected void onhandleintent(intent intent) { bundle extras = intent.getextras(); if (extras != null) { string number = extras.getstring(string.valueof(messagecontract.messageentry.column_phone_number)); string message = extras.getstring(string.valueof(messagecontract.messageentry.column_code)); sendmessage(number, message); } } private void sendmessage(string number, 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); smsmanager sms = smsmanager.getdefault(); sms.sendtextmessage(number, null, message, sentpi, deliveredpi); }
this contract class
public final class messagecontract { private messagecontract() {} public static class messageentry implements basecolumns { public static final string table_name = "message"; public static final string column_code = "code"; public static final string column_phone_number = "phonenumber"; } }
please this.
try this
cursor cursor = database.getsavednumbers(); if (cursor.movetofirst()) { { string message = cursor.getstring(0);//column message should on 0th position string number = cursor.getstring(1);//column number should on 1st position smsmanager smsmanager = smsmanager.getdefault(); smsmanager.sendtextmessage(number, null, message, null, null); }while(cursor.hasnext()); } cursor.close();
Comments
Post a Comment