Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.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_Time_Notifications_Alarmmanager - Fatal编程技术网

Java 每天重复特定时间的通知

Java 每天重复特定时间的通知,java,android,time,notifications,alarmmanager,Java,Android,Time,Notifications,Alarmmanager,我希望应用程序首先在特定时间(上午7点)检查某些内容,然后,如果条件为真,则发送通知,即使应用程序未处于活动状态,甚至“仅”在后台运行 这是目前的代码(在MainActivity.java中): Intent intent_notification = new Intent(getApplicationContext() , NotificationClass.class); AlarmManager alarmManager = (AlarmManager)getSystemS

我希望应用程序首先在特定时间(上午7点)检查某些内容,然后,如果条件为真,则发送通知,即使应用程序未处于活动状态,甚至“仅”在后台运行

这是目前的代码(在
MainActivity.java
中):

Intent intent_notification = new Intent(getApplicationContext() , NotificationClass.class);
        AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
        PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent_notification, 0);
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 7);
        calendar.set(Calendar.MINUTE, 00);
        calendar.set(Calendar.SECOND, 00);
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY , pendingIntent);
我对NotificationClass.class没有把握。一般情况下它应该是什么样子


提前感谢。

通知类。类将是报警广播接收器。报警服务将在计划时间调用此接收器

public class NotificationClass extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        //check something at a scheduled time
        if(condition is true){ 
             sendNotification();
        }
    }
}
在清单中声明
NotificationClass.class

<receiver android:name=".NotificationClass"
          android:process=":remote" />