在我的应用程序中,我为创建一个UILocalNotification所需的每个事件都有多个事件,例如我想在父亲节,母亲和一些节日上表达祝福。所以我已经有了特定的日期,我想在特定的日子解雇它,请该怎么做。我已经完成了单个UILocalNotification。现在我需要多个火灾日期。
如果我评论它在特定时间开火的日期。现在日期与时间不起作用。 现在问题如何在同一活动中添加多个日期和时间我想要发送通知。
任何人都可以帮助我。
MyView类
public class MyView extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Calendar firingCal = Calendar.getInstance();
firingCal.set(Calendar.MONTH, 7);
firingCal.set(Calendar.YEAR, 2014);
firingCal.set(Calendar.DAY_OF_MONTH, 9);
firingCal.set(Calendar.HOUR_OF_DAY, 16);
firingCal.set(Calendar.MINUTE, 35);
firingCal.set(Calendar.SECOND, 0);
// MyView is my current Activity, and AlarmReceiver is the
// BoradCastReceiver
Intent myIntent = new Intent(MyView.this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MyView.this,
0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
/*
* The following sets the Alarm in the specific time by getting the long
* value of the alarm date time which is in calendar object by calling
* the getTimeInMillis(). Since Alarm supports only long value , we're
* using this method.
*/
alarmManager.set(AlarmManager.RTC_WAKEUP, firingCal.getTimeInMillis(),
pendingIntent);
}
}
MyAlarmService类
public class MyAlarmService extends Service
{
private NotificationManager mManager;
@Override
public IBinder onBind(Intent arg0)
{
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate()
{
// TODO Auto-generated method stub
super.onCreate();
}
@SuppressWarnings("static-access")
@Override
public void onStart(Intent intent, int startId)
{
super.onStart(intent, startId);
mManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
Intent intent1 = new Intent(this.getApplicationContext(),MainActivity.class);
Notification notification = new Notification(R.drawable.ic_launcher,"This is a test message!", System.currentTimeMillis());
intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(),0, intent1,PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(this.getApplicationContext(), "AlarmManagerDemo", "This is a test message!", pendingNotificationIntent);
mManager.notify(0, notification);
}
@Override
public void onDestroy()
{
// TODO Auto-generated method stub
super.onDestroy();
}
}