我想在第二天设置我的通知警报在9点左右,但我无法设置

时间:2017-03-06 04:36:47

标签: java android notifications

 Calendar firingCal = Calendar.getInstance();
        Intent myInten = new Intent(Report_Activity.this, MyReceiver.class);
        final int intent_id_two = (int) System.currentTimeMillis();
        Calendar now = Calendar.getInstance();
        AlarmManager alarmManager = (AlarmManager) Report_Activity.this.getSystemService(Report_Activity.ALARM_SERVICE);
        PendingIntent myPendingIntent = PendingIntent.getBroadcast(Report_Activity.this, intent_id_two, myInten, PendingIntent.FLAG_CANCEL_CURRENT);


        firingCal.set(Calendar.HOUR_OF_DAY, 00);
        firingCal.set(Calendar.MINUTE, 01);
        firingCal.set(Calendar.SECOND, 0);
        if (firingCal.compareTo(now) < 0) {
            firingCal.add(Calendar.DAY_OF_MONTH, 1);
            myInten.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
            Bundle bundle = new Bundle();
            bundle.putString("date", str_view_date);
            bundle.putString("time", str_view_time);
            bundle.putString("school_name", str_show_school_name);
            bundle.putInt("intent_id", intent_id_two);
            myInten.putExtras(bundle);
            alarmManager.setRepeating(AlarmManager.RTC, firingCal.getTimeInMillis(),AlarmManager.INTERVAL_DAY, myPendingIntent);

        } else {
            myInten.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
            Bundle bundle = new Bundle();
            bundle.putString("date", str_view_date);
            bundle.putString("time", str_view_time);
            bundle.putString("school_name", str_show_school_name);
            bundle.putInt("intent_id", intent_id_two);
            myInten.putExtras(bundle);
            alarmManager.setRepeating(AlarmManager.RTC, firingCal.getTimeInMillis(),AlarmManager.INTERVAL_DAY, myPendingIntent);
        }
    }

这是我的Receiver Class

 int num = (int) System.currentTimeMillis();
        Bundle bundle = intent.getExtras();
        date = bundle.getString("date");
        time = bundle.getString("time");
        school_name = bundle.getString("school_name");
       // int notifyId = 1;
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Intent notificationIntent = new Intent(context, MainActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        //final int intent_id = (int) System.currentTimeMillis();
        pendingIntent = PendingIntent.getActivity(context, num, notificationIntent, 0);
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setContentTitle("Notification From Dextro");
        builder.setContentText("Meeting Schedule at " + school_name + " on " + date + " and time is " + time);
        builder.setSmallIcon(R.mipmap.dextro_customerlogo);
        builder.setContentIntent(pendingIntent);
        builder.setAutoCancel(true);
        builder.setSound(alarmSound);
        builder.setTicker("Notification From Dextro");
        builder.setStyle(new NotificationCompat.BigTextStyle()
                .bigText("Meeting Schedule at " + school_name + " on " + date + " and time is " + time));
        builder.setVibrate(new long[]{100, 100, 100, 100});
        notificationManager.notify(num, builder.build());
//notifyId++;
    }

我想在第二天设置通知,但我没有收到,但是当我今天设置闹钟然后我收到通知。我应该做什么改变我这个。如果我在24小时范围内设置闹钟那么我就是收到通知,但当我第二天去设置闹钟然后它没有收到请建议我..

2 个答案:

答案 0 :(得分:0)

您从未使用过notifyID

    var dataEntries: [BarChartDataEntry] = []
    let visitorCounts = getVisitorCountsFromDatabase() //read realm DB here

    var xAxisCount = visitorCounts.count 
    if xAxisCount > 10{
        xAxisCount = visitorCounts.count - 10
    }
    for i in xAxisCount..<visitorCounts.count {
        let timeIntervalForDate: TimeInterval = visitorCounts[i].date.timeIntervalSince1970
        let dataEntry = BarChartDataEntry(x: Double(timeIntervalForDate), y: Double(visitorCounts[i].count))
        dataEntries.append(dataEntry)
    }

答案 1 :(得分:0)

如果要显示新通知,则需要提供新的通知ID。如果您保留相同的ID,则会更新现有ID。

您问题中的Actuall代码

var UsersContext = new ApplicationDbContext();
List<ApplicationUser> = UsersContext.Users.toList()

您需要使用notifyId

替换1
notificationManager.notify(1, builder.build());