Android- setPeriodic for JobScheduler won't work

I think your problem is the frequency you would like to execute your job. The minimum period for a job is 15 minutes in the standard AOSP. So it probably isn't the right API for you. Alarm Manager would probably be what you want, but setting an alarm for every 5 seconds is expensive. Google has also been restricting background services more and more with each release. Just something to keep in mind.

See: JobScheduler not repeating job


setPeriodic(long intervalMillis) only works on devices lower than Nougat change it with this setPeriodic (long intervalMillis, long flexMillis) for devices having android version Nougat and above.