AlarmManager - Notification in time

0

I'm trying to trigger an on-screen message through AlamManager and BroadCastReceiver .

The specific time is being taken by a TimePicker exactly as it should.

But the notification does not go off the screen.

The code looks like this:

@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 BroadcastReceiver class looks like this:

public class AlarmReceiver extends BroadcastReceiver 
{
    @Override
    public void onReceive(Context arg0, Intent arg1) {
        Toast.makeText(arg0, "Your Time is up!!!!!", Toast.LENGTH_LONG).show();
    }
}
    
asked by anonymous 26.05.2014 / 14:59

1 answer

1

Include <receiver> in AndroidManifest.xml :

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