I am a newbie in android development and currently developing a Reminder appfor showing the notifications every 15 mins, when charging and connected to wifi . Although the notification is showing every 15 mins. But the conditions for showing notification only when charging and when connected to wifi are not working. So it shows notifications even when not charging or not connected to wifi. I have used the below code for scheduling it.
public class ReminderUtilities {
private static final int REMINDER_INTERVAL_TIME = 15;
private static final int REMINDER_INTERVAL_MILLIS = (int) (TimeUnit.MINUTES.toMillis(REMINDER_INTERVAL_TIME));
private static boolean mInitialized ;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
synchronized public static void scheduleTaskReminder(Context context) {
if( mInitialized ) {
return;
}
ComponentName serviceComponent = new ComponentName(context, WaterReminderJobService.class);
JobInfo.Builder builder = new JobInfo.Builder(0, serviceComponent)
.setPeriodic(REMINDER_INTERVAL_MILLIS)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
.setRequiresCharging(true);
JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
scheduler.schedule(builder.build());
mInitialized = true;
}
}