0
I’m trying to make an app that arrives notifications at user-determined times every day, but I was only able to make them arrive once.
That’s the code I’ve got so far:
private void salvar() {
RespostasAguaCasa p = new RespostasAguaCasa();
p.setId(1);
p.setValoragua(QuintaperguntaAguaCasa.valoragua);
p.setAcordarhora(EscolhaAguaCasa.hourx);
p.setAcordarminu(EscolhaAguaCasa.minutex);
p.setDormirhora(SegundaperguntaAguaCasa.hourxx);
p.setDormirminu(SegundaperguntaAguaCasa.minutexx);
p.setTerceirahora(TerceiraperguntaAguaCasa.hourxxx);
p.setTerceiraminu(TerceiraperguntaAguaCasa.minutexxx);
p.setQuartahora(QuartaperguntaAguaCasa.hourxxxx);
p.setQuartaminu(QuartaperguntaAguaCasa.minutexxxx);
p.setQuintahora(QuintaperguntaAguaCasa.hourxxxxx);
p.setQuintaminu(QuintaperguntaAguaCasa.minutexxxxx);
Calendar calNow = Calendar.getInstance();
Calendar calSet = (Calendar) calNow.clone();
calSet.setTimeInMillis(System.currentTimeMillis());
calSet.set(Calendar.HOUR_OF_DAY , EscolhaAguaCasa.hourx);
calSet.set(Calendar.MINUTE, EscolhaAguaCasa.minutex);
calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 0);
setAlarm(calSet);
}
Alarm:
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(arg0)
.setSmallIcon(R.drawable.casa)
.setContentTitle("ads")
.setContentText("sad")
.setAutoCancel(true)
;
NotificationManager notificationManager = (NotificationManager) arg0.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, builder.build());
}
}
setAlarm
is in the same class as the salvar
:
public 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(), 1, intent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, targetCall.getTimeInMillis(), pendingintent);
}
it is asking for a Setter on the following line or asks for static and turns a Error Loopy setAlarm(calSet); what do ?
– aleander rayson
I guess I didn’t put my class set Larm I’ll put it in the post
– aleander rayson
@aleanderrayson Probably this setAlarm is in its original code.
– Julio Borges
I guess I hadn’t edited him out .
– aleander rayson
@aleanderrayson, includes the method in the notification class
– Julio Borges
I had tried this yesterday but now she is with another mistake I created another question about if I can take a look . Thank you ! https://answall.com/questions/313306/como-usar-o-getsystemservice-n%C3%A3o-est%C3%A1tico
– aleander rayson
@aleanderrayson, I answered there, if it works, mark the answers as valid
– Julio Borges
gave proper thank you
– aleander rayson