我正在制作一个短信日程应用程序,它只需要用户的时间、短信和号码,并在给定时间发送此短信。我正在使用PendingIntent
. 这是我的示例代码。
当用户创建计划时,它只是调用此方法。
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);
}
这是“SMSBroadcastReceiver.java”文件
public class SMSBroadcastReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "SMS Sent !!!!.", Toast.LENGTH_LONG)
.show();
// //Sms Sending
try
{
SmsManager smsManager = SmsManager.getDefault();
for (int i = 0; i < SMSScheduleContactsActivity.SelectedContacts.length; i++)
{
smsManager.sendTextMessage(
SMSScheduleContactsActivity.SelectedContacts[i], null,
AddNewSmsSchedule.Message, null, null);
}
Log.d("testllllllllllllllll", "Message Sent");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
我的问题是:当用户编辑时间表时,我怎样才能取消该广播并发送一个新的?由于可以有多个时间表,如何找到具体的更改/中止?