Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通知不';“活动”关闭时不显示_Java_Android_Android Intent_Notifications_Android Pendingintent - Fatal编程技术网

Java 通知不';“活动”关闭时不显示

Java 通知不';“活动”关闭时不显示,java,android,android-intent,notifications,android-pendingintent,Java,Android,Android Intent,Notifications,Android Pendingintent,我想在一年中的某一天发出通知。我似乎不知道如何使用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;..

我想在一年中的某一天发出通知。我似乎不知道如何使用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);

    }

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

API是AlarmManager?是。它基本上允许您设置一个PendingEvent,当时间流逝时将调用它。您可以让它使用超精确版本,也可以使用精度较低的版本。对于你的情况,我会用不太准确的,几秒钟也没关系。请注意,这在重新启动时不起作用,要做到这一点,您必须让广播接收器收听BOOT_COMPLETE并启动您的服务。