0

特定の時間と分まで鳴らないアラームがあります。ただし、その時が来ると、アプリを再起動するたびにオフになります。(アプリが起動すると、リセットされ、新しいアラームを確認します)。

たとえば、午前9時48分にオフになります。9:48より前は、期待どおりに何も起こりません。ただし、9:48以降は、アプリが起動するたびにオフになります(アラームは単純なステータスバー通知です)。

ここにコードがあります-どこで間違ったのですか?

//ここにアラームを設定-このコードは、アプリが起動するたびに呼び出されます

public void setAlarm() {
 for (int i : AlarmDays) {

        Calendar cal = Calendar.getInstance();
        if (cal.get(Calendar.DAY_OF_MONTH) > i)
            cal.add(Calendar.MONTH, 1);
        cal.set(Calendar.DAY_OF_MONTH, i);
        cal.set(Calendar.HOUR, 9);
        cal.set(Calendar.MINUTE, 53);
        cal.set(Calendar.SECOND, 1);


        String Name = AlarmNames.get(count);
        count = 0 + 1;

        Intent intent = new Intent(ManageDebts.this, TimeAlarm.class);
        Bundle b = new Bundle();
        b.putString("keyvalue", Name);
        intent.putExtras(b);


        pendingIntent = PendingIntent.getBroadcast(this, i,
                intent, PendingIntent.FLAG_CANCEL_CURRENT);
        am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
                pendingIntent);

    }
 }

TimeAlarm.class

public class TimeAlarm extends BroadcastReceiver {

NotificationManager nm;

@Override
public void onReceive(Context context, Intent intent) {

    String DebtName = intent.getStringExtra("keyvalue");

    nm = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence from = "Payment Due: " + DebtName;
    CharSequence message = "Update your Balance Now";
    Intent notificationIntent = new Intent(context, ManageDebts.class);
    notificationIntent.getExtras();
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            notificationIntent, 0);
    Notification notif = new Notification(R.drawable.icon, "Pay "
            + DebtName + " today!", System.currentTimeMillis());
    notif.setLatestEventInfo(context, from, message, contentIntent);
    notif.defaults = Notification.DEFAULT_SOUND
            | Notification.DEFAULT_LIGHTS;
    notif.flags = Notification.FLAG_SHOW_LIGHTS;
    notif.ledOnMS = 100;
    notif.ledOffMS = 100;
    notif.flags |= Notification.FLAG_AUTO_CANCEL;
    nm.notify(1, notif);
}

}

4

1 に答える 1

1

その分、時間、秒にないアラームを無視するように設定するにはどうすればよいですか?前または後?

あなたのsetAlarm()方法で。AlarmDaysループに入る前にフィルターで除外するか、比較cal.getTimeInMillis()System.currentTimeMillis()て過去のものかどうかを確認します。

于 2012-06-15T19:38:28.867 に答える