Alarmmanager - Time-specific notification

Asked

Viewed 435 times

0

I’m trying to trigger a message on the screen through the AlamManager and BroadCastReceiver.

The specific time is being picked up by a TimePicker exactly as you should.

But the notification ends up not being fired on the screen.

The code is that way:

@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) 
{
    Calendar calNow = Calendar.getInstance();
    Calendar calSet = (Calendar) calNow.clone();
    calSet.setTimeInMillis(System.currentTimeMillis());
    calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
    calSet.set(Calendar.MINUTE, minute);
    calSet.set(Calendar.SECOND, 0);
    calSet.set(Calendar.MILLISECOND, 0);

    setAlarm(calSet);
}

private void setAlarm(Calendar targetCall)
    {
        Toast.makeText(this, "Alarm is set at" + targetCall.getTime(),
                Toast.LENGTH_LONG).show();
        Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);

        PendingIntent pendingintent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0);
        AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);

        alarmManager.set(AlarmManager.RTC_WAKEUP, targetCall.getTimeInMillis(), pendingintent);
    }

And the class of BroadcastReceiver is that way:

public class AlarmReceiver extends BroadcastReceiver 
{
    @Override
    public void onReceive(Context arg0, Intent arg1) {
        Toast.makeText(arg0, "Your Time is up!!!!!", Toast.LENGTH_LONG).show();
    }
}
  • 2

    Your class AlarmReceiver is stated in the AndroidManifest.xml? <receiver android:name="pacote.onde.está.a.classe.AlarmReceiver" />

  • I wasn’t with receiver, I didn’t pay attention to that, thank you :D

  • Now everything is as it should :D

  • Okay, I’ll put it in answer.

1 answer

1


Include the <receiver> in the AndroidManifest.xml:

<receiver android:name="pacote.onde.está.a.classe.AlarmReceiver" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.