2

我的应用程序中有一个功能,用户可以设置多个提醒。但问题是,当用户为提醒 A 设置时间而不是为提醒 B 设置时间时,提醒 B 只会被调用。这就是提醒 A 永远不会接到电话的意图。简而言之,只有一个提醒一直在工作。这是设置提醒和呼叫广播的片段。

public void setAlarm(int dayValue, int monthValue, int yearValue, int hourValue, int minValue, String message, int pos){

            int ID = 1;
        calendar.set(yearValue, monthValue, dayValue, hourValue, minValue, 0);
        Calendar tempCal = Calendar.getInstance();
        Intent intent = new Intent(context,ReminderNissan.class);

        intent.putExtra("title",message);
        intent.putExtra("note",message);
        intent.putExtra("id", pos);

        Log.d("****Indide set alarm method*****", "PSOITION " + pos);

        if((tempCal.compareTo(calendar)==  -1) || (tempCal.compareTo(calendar)==  0)){
            try{
                db.open();
                db.setAlarm(id.get(pos).toString(), 1);
                db.close();
            }catch(SQLException exp){
                Log.d("SET ALARM OFF SQL EXCEPTION", exp.toString());
            }

            PendingIntent sender = PendingIntent.getBroadcast(context, ID,intent,0);

            am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
            //Toast.makeText(context, "*** ALARM SET AT ***  " + pos, Toast.LENGTH_SHORT).show();

        }else{
            try{
                db.open();
                db.setAlarm(id.get(pos).toString(), 0);
                db.close();
            }catch(SQLException exp){
                Log.d("SET ALARM OFF SQL EXCEPTION", exp.toString());
            }
            Toast.makeText(context, "Time Has Alredy Passed. Set proper Time. ", Toast.LENGTH_SHORT).show();
        }
    }
4

2 回答 2

1

我不完全确定,但可能是您正在覆盖警报。

PendingIntent sender = PendingIntent.getBroadcast(context, ID,intent,0);

在您的情况下, ID 参数始终为 1。只需将其设为唯一的 id 就可以了。

于 2013-01-17T08:27:42.290 回答
0

您在哪里调用了您的 setAlarm-Method?我有一个应用程序,它以类似的方式工作,每次警报处于活动状态时,我都会打开一个带有取消按钮的活动。通过按下按钮,它将再次设置 setAlarm-Method,因此它将前进到下一个警报。为此,我为 pendingIntent 设置了一个标志

      PendingIntent sender = PendingIntent.getBroadcast(context, ID,intent,PendingIntent.FLAG_UPDATE_CURRENT );
于 2013-01-17T08:36:59.350 回答