Notification not sent by JobService
Notification not sent by JobService
So I have a notification set up in my JobService.class
and I know for sure that it works. The problem is that I don't think my JobService
is ever getting called. I want my app to check the database every couple hours and if it matches certain criterias it will send a notification. I start my JobService
like this in my MainActivity
:
JobService.class
JobService
JobService
MainActivity
ComponentName componentName = new ComponentName(MainActivity.this, JobService.class);
JobInfo info = new JobInfo.Builder(6484, componentName)
.setPeriodic(1000 * 60 * 15)
.build();
JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
if (scheduler != null) {
scheduler.schedule(info);
}
And this is my JobService
since it's too long. I cut off the code for the notification parts because it's too long.
JobService
@Override
public boolean onStartJob(JobParameters jobParameters) {
{//when it matches the criteria and the notification is sent
jobFinished(jobParameters, false);
}
return true;
}
@Override
public boolean onStopJob(JobParameters jobParameters) {
if (databaseReference != null && valueEventListener != null) {
databaseReference.removeEventListener(valueEventListener);
}
return false;
}
PS. I'm sure my notification works because before I was using the Service class and it would send the notification. I just had to switch because it would not check for updates in the background.
Why?
I actually have I just didn't post it again. I think it's the job not being called. IfI you want I can post the whole code but as an image because it is quite long.
– Kristofer
Jun 30 at 19:53
Add some stdouts in the job and you'll know if its called or not
– jammaster
Jul 1 at 12:33
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
If you are targeting SDK 26 the notification API changed and notifications will not display if you did not provide a channel for it. In developer options, you can tick "Show notification channel warnings" which will display a toast when this is the case. Otherwise I don't think we have enough to go on here.
– jammaster
Jun 30 at 19:50