0
I want my app to send notifications once a day, so I’m using Jobscheduler that looks newer (I’ve tried alarmmanager and there were other errors). However, I’m not getting any notifications, nothing at all. Job starts when the person clicks on a button. Note that I put the 50s setPeriod as a test.
public void agendarJob(View view){
JobScheduler scheduler = (JobScheduler) getBaseContext()
.getSystemService(Context.JOB_SCHEDULER_SERVICE);
ComponentName serviceName = new ComponentName(getBaseContext(), ServicoAlarme.class);
JobInfo jobInfo = new JobInfo.Builder(1,serviceName)
.setPeriodic(50000)
.setRequiresCharging(false)
.setPersisted(true)
.build();
scheduler.schedule(jobInfo);
int result = scheduler.schedule(jobInfo);
if(result == JobScheduler.RESULT_SUCCESS){
Log.d("Notificacao","Serviço Agendado");
textvAtualizacao.setText("Notificação está agendada!");
}
and then send it to the Servicoalarme class.
public class ServicoAlarme extends JobService {
@Override
public boolean onStartJob(JobParameters params) {
Intent intentNotificacao = new Intent(getBaseContext(), splashscreenveg.class);
int idNotification = 1;
PendingIntent pedingIntentNotification = PendingIntent.getActivity(getBaseContext(), idNotification, intentNotificacao, PendingIntent.FLAG_UPDATE_CURRENT);
Notification lembretedeestudo = new Notification.Builder(getBaseContext())
.setContentTitle("Lembrete!")
.setContentText("Está na hora de estudar inglês!")
.setSmallIcon(R.mipmap.ic_visualenglishgrammar7_round)
.setContentIntent(pedingIntentNotification).build();
NotificationManager notificationManager = (NotificationManager) getBaseContext().getSystemService(getBaseContext().NOTIFICATION_SERVICE);
lembretedeestudo.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(idNotification,lembretedeestudo);
return true;
}
@Override
public boolean onStopJob(JobParameters params) {
return false;
}
}
And in my manifesto it’s like this:
<service android:name=".ServicoAlarme"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true"/>
I can’t find the error, if someone can help me and explain well, because I’m a beginner, it would be perfect. Thank you :)