use of android.app.job.JobScheduler in project cw-omnibus by commonsguy.
the class EventDemoActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getFragmentManager().findFragmentById(android.R.id.content) == null) {
getFragmentManager().beginTransaction().add(android.R.id.content, new EventLogFragment()).commit();
JobScheduler jobs = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
ComponentName cn = new ComponentName(this, ScheduledService.class);
JobInfo.Builder b = new JobInfo.Builder(JOB_ID, cn).setRequiredNetworkType(JobInfo.NETWORK_TYPE_NONE).setPeriodic(60000).setPersisted(false).setRequiresCharging(false).setRequiresDeviceIdle(false);
jobs.schedule(b.build());
}
}
use of android.app.job.JobScheduler in project materialistic by hidroh.
the class SyncDelegate method scheduleSync.
@UiThread
public static void scheduleSync(Context context, Job job) {
if (!Preferences.Offline.isEnabled(context)) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !TextUtils.isEmpty(job.id)) {
JobInfo.Builder builder = new JobInfo.Builder(Long.valueOf(job.id).intValue(), new ComponentName(context.getPackageName(), ItemSyncJobService.class.getName())).setRequiredNetworkType(Preferences.Offline.isWifiOnly(context) ? JobInfo.NETWORK_TYPE_UNMETERED : JobInfo.NETWORK_TYPE_ANY).setExtras(job.toPersistableBundle());
if (Preferences.Offline.currentConnectionEnabled(context)) {
builder.setOverrideDeadline(0);
}
((JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(builder.build());
} else {
Bundle extras = new Bundle(job.toBundle());
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
Account syncAccount;
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccountsByType(BuildConfig.APPLICATION_ID);
if (accounts.length == 0) {
syncAccount = new Account(SYNC_ACCOUNT_NAME, BuildConfig.APPLICATION_ID);
accountManager.addAccountExplicitly(syncAccount, null, null);
} else {
syncAccount = accounts[0];
}
ContentResolver.requestSync(syncAccount, MaterialisticProvider.PROVIDER_AUTHORITY, extras);
}
}
use of android.app.job.JobScheduler in project materialistic by hidroh.
the class ItemSyncJobServiceTest method testScheduledJob.
@Test
public void testScheduledJob() {
PreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application).edit().putBoolean(RuntimeEnvironment.application.getString(R.string.pref_saved_item_sync), true).apply();
shadowOf((ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE)).setActiveNetworkInfo(ShadowNetworkInfo.newInstance(null, ConnectivityManager.TYPE_WIFI, 0, true, true));
SyncDelegate.scheduleSync(RuntimeEnvironment.application, new SyncDelegate.JobBuilder(RuntimeEnvironment.application, "1").build());
List<JobInfo> pendingJobs = shadowOf((JobScheduler) RuntimeEnvironment.application.getSystemService(Context.JOB_SCHEDULER_SERVICE)).getAllPendingJobs();
assertThat(pendingJobs).isNotEmpty();
JobInfo actual = pendingJobs.get(0);
assertThat(actual.getService().getClassName()).isEqualTo(ItemSyncJobService.class.getName());
}
use of android.app.job.JobScheduler in project muzei by romannurik.
the class ArtworkComplicationJobService method scheduleComplicationUpdateJob.
static void scheduleComplicationUpdateJob(Context context) {
JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
ComponentName componentName = new ComponentName(context, ArtworkComplicationJobService.class);
int result = jobScheduler.schedule(new JobInfo.Builder(ARTWORK_COMPLICATION_JOB_ID, componentName).addTriggerContentUri(new JobInfo.TriggerContentUri(MuzeiContract.Artwork.CONTENT_URI, JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS)).build());
if (BuildConfig.DEBUG) {
Log.d(TAG, "Job scheduled with " + (result == JobScheduler.RESULT_SUCCESS ? "success" : "failure"));
}
// Enable the BOOT_COMPLETED receiver to reschedule the job on reboot
ComponentName bootReceivedComponentName = new ComponentName(context, ArtworkComplicationBootReceiver.class);
context.getPackageManager().setComponentEnabledSetting(bootReceivedComponentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}
use of android.app.job.JobScheduler in project muzei by romannurik.
the class ArtworkComplicationJobService method cancelComplicationUpdateJob.
static void cancelComplicationUpdateJob(Context context) {
JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
jobScheduler.cancel(ARTWORK_COMPLICATION_JOB_ID);
if (BuildConfig.DEBUG) {
Log.d(TAG, "Job cancelled");
}
// Disable the BOOT_COMPLETED receiver to reduce memory pressure on boot
ComponentName bootReceivedComponentName = new ComponentName(context, ArtworkComplicationBootReceiver.class);
context.getPackageManager().setComponentEnabledSetting(bootReceivedComponentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
Aggregations