Android 我想在安卓系统中启动带有特定日期时间的通知

Android 我想在安卓系统中启动带有特定日期时间的通知,android,notifications,Android,Notifications,在我的应用程序中,我为每个需要创建一个UILocalNotification的事件创建了多个事件,例如,我想在父亲节、母亲节和一些节日表达愿望。所以我已经有了具体的日期,现在我想在特定的日子发射它,请如何做到这一点。我已经为单个UILocalNotification做了很多工作。现在我需要多个火灾日期 如果我评论它在特定时间开火的日期。现在,带时间的日期不起作用。 现在的问题是如何在同一个活动中添加多个日期和时间我想触发通知 谁能帮帮我吗 MyView类 public class MyView

在我的应用程序中,我为每个需要创建一个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);
    }
}
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();
    }

}
MyAlarmService类别

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);
    }
}
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();
    }

}

检查此项:。希望这有帮助。嗨,我想在我的代码中显示日期选择器我想设置一些静态日期已经在提供的链接中。日期选择器正在显示,如果我设置日期意味着发送通知。但是我想在代码本身中设置一些日期和时间我想触发通知,你能告诉我吗