我正在尝试发出通知,以在一年中的某一天出现。我似乎无法弄清楚如何获得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);

    }

最佳答案

您需要设置一个警报。您无法在“活动”中执行类似的操作。您应该在服务中设置该警报,因为在活动中执行此操作会使该警报在活动完成后丢失。

08-17 10:20