即使在Android中杀死应用程序后,也会显示状态栏通知

时间:2013-01-04 17:01:13

标签: android notifications alarmmanager kill

我必须在我的申请中提出不同类型的通知。即使应用程序从任务管理器中被终止,也应显示通知。通知应该一个接一个地堆叠。我正在使用的现有通知代码如下所示。

这是用于创建通知的类:

public class TimeAlarm extends BroadcastReceiver {

     NotificationManager nm;

     @Override
     public void onReceive(Context context, Intent intent) {
      nm = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
      CharSequence from = "Scheduled Training";
      CharSequence message = "Please attend the scheduled training";


      PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
        new Intent(), 0);
      Notification notif = new Notification(R.drawable.ic_launcher,
        "Scheduled Training", System.currentTimeMillis());
      notif.setLatestEventInfo(context, from, message, contentIntent);
      nm.notify(1, notif);
     }
    }

这是我在活动中使用的代码,用于创建通知:

  @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

  duration=(EditText)findViewById(R.id.duration_editText);
        dateAndTimeLabel=(TextView)findViewById(R.id.timeTxt);

        updateLabel();
        updateNotification();
        am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

     // On Click Confirm

            confirm=(ImageView)findViewById(R.id.confirm_imageView);
            confirm.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    getDateTime();
                     count++;
                   setOneTimeAlarm();
                }
            });

      }


     public void setOneTimeAlarm() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour);
             calendar.set(Calendar.MINUTE, minute);
             calendar.set(Calendar.SECOND, 0);





          Intent intent = new Intent(this, TimeAlarm.class);
          PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
            intent,count);
          am.set(AlarmManager.RTC_WAKEUP,
           calendar.getTimeInMillis(), pendingIntent);
         }


    void updateNotification()
          {
              hour= dateAndTime.get(Calendar.HOUR_OF_DAY);
              minute=dateAndTime.get(Calendar.MINUTE);
          }

这无助于我实现目标。我该怎么办?我想创建一种你可以在冰河时代乡村游戏中找到的通知。

0 个答案:

没有答案