There can be many ways but one is to use WorkManager for this purpose. You can schedule or repeatedly perform operation of sending data from one app to another.
Beauty of WorkManager
is that WorkManager
might use JobScheduler
, Firebase JobDispatcher
, or AlarmManager
. You don't need to write device logic to figure out what capabilities the device has and choose an appropriate API; instead, you can just hand your task off to WorkManager and let it choose the best option.
Your requirement comes under Recurring tasks
:
Usage is like this:
new PeriodicWorkRequest.Builder photoCheckBuilder =
new PeriodicWorkRequest.Builder(PhotoCheckWorker.class, 12,
TimeUnit.HOURS);
// ...if you want, you can apply constraints to the builder here...
// Create the actual work object:
PeriodicWorkRequest photoCheckWork = photoCheckBuilder.build();
// Then enqueue the recurring task:
WorkManager.getInstance().enqueue(photoCheckWork);