过期列表对象的通知

时间:2017-09-20 15:14:47

标签: android listview notifications

我想知道如何在1天左右后发送通知。我的ArrayList包含一个String和添加它的日期。我在网上搜索但是没有找到类似的东西。在列表对象上我需要像监听器那样的时间。希望你们比我更清楚:))

1 个答案:

答案 0 :(得分:0)

所以我过了一会儿就发现了。 您只需要AlarmManager和待处理的Intents!

我的方法如下:

   private void startAlarm(boolean isNotification, boolean isRepeat,int year, int month, int day) {
    AlarmManager manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
    Intent myIntent;
    PendingIntent pendingIntent;

    Calendar myAlarmDate = Calendar.getInstance();
    myAlarmDate.setTimeInMillis(System.currentTimeMillis());
    myAlarmDate.set(year, month, day-1, 10, 00, 0);


    if(!isNotification)
    {
        myIntent = new Intent(this,AlarmToastReceiver.class);
        pendingIntent = PendingIntent.getBroadcast(this,0,myIntent,0);
    }
    else{
        myIntent = new Intent(this,AlarmNotificationReceiver.class);
        pendingIntent = PendingIntent.getBroadcast(this,0,myIntent,0);
    }

     if(!isRepeat) {
         manager.set(AlarmManager.RTC_WAKEUP,/* myAlarmDate.getTimeInMillis()*/1000, pendingIntent);
         Log.d("alarm", "1");
     }
    else{
        manager.setRepeating(AlarmManager.RTC_WAKEUP,SystemClock.elapsedRealtime()+3000,60*1000,pendingIntent);
    Log.d("alarm", "2"); }
}