I am making an SMS schedule application that will simply take time, sms and number from the user and send this sms at the set time. I am using PendingIntent . Here is my sample code.
When the user creates a schedule, he simply calls this method.
private void SendMessages() { Intent intent = new Intent(this, SMSBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast( this.getApplicationContext(), 234324243, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, Timemilli, pendingIntent); }
And here is the file 'SMSBroadcastReceiver.java'
public class SMSBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "SMS Sent !!!!.", Toast.LENGTH_LONG) .show();
My question is: when a user edits a schedule, how can I cancel this broadcast and send a new one? Since there can be more than one schedule, how to find speicific for change / interrupt?
android android-pendingintent broadcastreceiver smsmanager
Ahmad abbasi
source share