我正在开发一个安排发送消息的 Android 应用程序。我正在使用警报管理器。我的主要部分代码如下:
mConfirm.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent =
new Intent(getApplicationContext(),MyNotificationService.class);
mMessage = mEditTextMessage.getText().toString();
mNumber = mEditTextNumber.getText().toString();
c.set(mYear, mMonth, mDay);
c.set(Calendar.HOUR_OF_DAY, mHour);
c.set(Calendar.MINUTE, mMinutes);
Bundle bundle = new Bundle();
bundle.putCharSequence("number", mNumber);
bundle.putCharSequence("message", mMessage);
intent.putExtras(bundle);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent =
PendingIntent.getService(getApplicationContext(), 0, intent, 0);
alarmManager.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(),
pendingIntent);
}
});
我应该如何实现 MyNotificationService 类,以便它在设定的时间发送消息?该类应该是服务还是广播接收器?