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();
}
}
Your class
AlarmReceiver
is stated in theAndroidManifest.xml
?<receiver android:name="pacote.onde.está.a.classe.AlarmReceiver" />
– Piovezan
I wasn’t with receiver, I didn’t pay attention to that, thank you :D
– Enzo Tiezzi
Now everything is as it should :D
– Enzo Tiezzi
Okay, I’ll put it in answer.
– Piovezan