I have an AlarmReceiver class which executes when alarm rings at a particular time (set in alarm)
I am sending sms inside AlarmReciever class but I am not able to register the reciever for SMS Sent.
here is the code
private int sendSMS(String messageToSend,String contactsToSend,Context context)
{
StringTokenizer tok=new StringTokenizer(contactsToSend);
int n=tok.countTokens();
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
final AlertDialog dialog = new AlertDialog.Builder(context).create();
PendingIntent sentPI = PendingIntent.getBroadcast(context, 0,new Intent(SENT), 0);
//---when the SMS has been sent---
**/*registerReceiver(new BroadcastReceiver**(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
break;
}
return;
}
}, new IntentFilter(SENT));*/
SmsManager sms = SmsManager.getDefault();
String phoneNumber;
for(int i=0;i<n;i++)
{
phoneNumber=tok.nextToken();
sms.sendTextMessage(phoneNumber, null, messageToSend, null,null);
}
return 1;
}
when i remove the comment from line (in bold) it gives error.
So how cam i register a reciever to check whether the sms was sent or not.
instead of registering reciever you can create a service like this