1

我试图发出通知,显示一年中某一天发生的情况。我似乎无法弄清楚如何获得Android。我怎样才能让android每天在这个应用程序上检查?活动关闭时不显示通知

cal = Calendar.getInstance(); 
    dayOfYear = cal.get(Calendar.DAY_OF_YEAR); 

    payDays = new int[12]; 

    payDays[0] = 60; 
    payDays[1] = 88; 
    payDays[2] = 123; 
    payDays[3] = 151;... 

    // Checks when to send the notification 
    if (dayOfYear == payDays[0] || 
     dayOfYear == payDays[1] || 
     dayOfYear == payDays[2] || 
     dayOfYear == payDays[3] || 

    { 

     Builder builder = new Notification.Builder(this) 
     .setContentTitle("Phone Commission") 
     .setContentText("Expand for totals") 
     .setSmallIcon(R.drawable.notify2); 


     Notification notification = new Notification.BigTextStyle(builder) 
       .bigText("Add-a-Line: " + AALNote + 
         "\nUpgrades: " + UPGNote + 
         "\nNew Lines: " + NLNote + 
         "\nYour total commission is: " + "$" + totalNote).build(); 

      NotificationManager notify = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
       notify.notify(0, notification); 

    } 

回答

0

您需要设置报警。你不能在活动中这样做。您应该在服务中设置该警报,因为在活动完成后,在活动中这样做会使其丢失。

+0

这个API是AlarmManager? – user1985295 2013-02-27 05:22:21

+0

是的。它基本上允许你设置一个PendingIntent,当时间流逝时会被调用。你可以让它使用超精确的版本或不太准确的版本。对于你的情况,我会使用不太准确的,几秒钟就不会有问题。请注意,这在重新启动时不起作用,为此,您必须让广播接收器收听BOOT_COMPLETE并启动您的服务。 – 2013-02-27 05:27:38

+0

感谢球员们的意见 – user1985295 2013-02-27 05:28:16

相关问题