List of usage examples for android.os PersistableBundle PersistableBundle
public PersistableBundle()
From source file:Main.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) public static PersistableBundle bundleToPersistableBundle(Bundle bundle) { Set<String> keySet = bundle.keySet(); PersistableBundle persistableBundle = new PersistableBundle(); for (String key : keySet) { Object value = bundle.get(key); if (value instanceof Boolean) { persistableBundle.putBoolean(key, (boolean) value); } else if (value instanceof Integer) { persistableBundle.putInt(key, (int) value); } else if (value instanceof String) { persistableBundle.putString(key, (String) value); } else if (value instanceof String[]) { persistableBundle.putStringArray(key, (String[]) value); } else if (value instanceof Bundle) { PersistableBundle innerBundle = bundleToPersistableBundle((Bundle) value); persistableBundle.putPersistableBundle(key, innerBundle); }/* w w w . j a v a 2s .co m*/ } return persistableBundle; }
From source file:com.example.android.sampletvinput.syncservice.SyncUtils.java
public static void setUpPeriodicSync(Context context, String inputId) { PersistableBundle pBundle = new PersistableBundle(); pBundle.putString(SyncJobService.BUNDLE_KEY_INPUT_ID, inputId); JobInfo.Builder builder = new JobInfo.Builder(PERIODIC_SYNC_JOB_ID, new ComponentName(context, SyncJobService.class)); JobInfo jobInfo = builder.setExtras(pBundle).setPeriodic(SyncJobService.FULL_SYNC_FREQUENCY_MILLIS) .setPersisted(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build(); scheduleJob(context, jobInfo);//from w w w . java 2s .c o m }
From source file:com.example.android.sampletvinput.syncservice.SyncUtils.java
public static void requestSync(Context context, String inputId, boolean currentProgramOnly) { PersistableBundle pBundle = new PersistableBundle(); pBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); pBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); pBundle.putString(SyncJobService.BUNDLE_KEY_INPUT_ID, inputId); pBundle.putBoolean(SyncJobService.BUNDLE_KEY_CURRENT_PROGRAM_ONLY, currentProgramOnly); JobInfo.Builder builder = new JobInfo.Builder(REQUEST_SYNC_JOB_ID, new ComponentName(context, SyncJobService.class)); JobInfo jobInfo = builder.setExtras(pBundle).setOverrideDeadline(SyncJobService.OVERRIDE_DEADLINE_MILLIS) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build(); scheduleJob(context, jobInfo);//from ww w. ja v a 2 s. c o m Intent intent = new Intent(SyncJobService.ACTION_SYNC_STATUS_CHANGED); intent.putExtra(SyncJobService.BUNDLE_KEY_INPUT_ID, inputId); intent.putExtra(SyncJobService.SYNC_STATUS, SyncJobService.SYNC_STARTED); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); }
From source file:com.google.android.car.kitchensink.job.JobSchedulerFragment.java
private void scheduleJob() { ComponentName jobComponentName = new ComponentName(getContext(), DishService.class); SharedPreferences prefs = getContext().getSharedPreferences(PREFS_NEXT_JOB_ID, Context.MODE_PRIVATE); int jobId = prefs.getInt(PREFS_NEXT_JOB_ID, 0); PersistableBundle bundle = new PersistableBundle(); int count = 50; try {/*from www .j a va2 s. c om*/ count = Integer.valueOf(mDishNum.getText().toString()); } catch (NumberFormatException e) { Log.e(TAG, "NOT A NUMBER!!!"); } int selected = mNetworkGroup.getCheckedRadioButtonId(); int networkType = JobInfo.NETWORK_TYPE_ANY; switch (selected) { case R.id.network_none: networkType = JobInfo.NETWORK_TYPE_NONE; break; case R.id.network_unmetered: networkType = JobInfo.NETWORK_TYPE_UNMETERED; break; case R.id.network_any: networkType = JobInfo.NETWORK_TYPE_ANY; break; } bundle.putInt(DishService.EXTRA_DISH_COUNT, count); JobInfo jobInfo = new JobInfo.Builder(jobId, jobComponentName) .setRequiresCharging(mRequireCharging.isChecked()).setRequiresDeviceIdle(mRequireIdle.isChecked()) // TODO: figure out why we crash here even we hold // the RECEIVE_BOOT_COMPLETE permission //.setPersisted(mRequirePersisted.isChecked()) .setExtras(bundle).setRequiredNetworkType(networkType).build(); mJobScheduler.schedule(jobInfo); Toast.makeText(getContext(), "Scheduled: " + jobInfo, Toast.LENGTH_LONG).show(); Log.d(TAG, "Scheduled a job: " + jobInfo); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(PREFS_NEXT_JOB_ID, jobId + 1); editor.commit(); refreshCurrentJobs(); }
From source file:eu.faircode.netguard.ServiceJob.java
public static void submit(Rule rule, Context context) { PersistableBundle bundle = new PersistableBundle(); bundle.putString("type", "rule"); bundle.putInt("wifi_default", rule.wifi_default ? 1 : 0); bundle.putInt("other_default", rule.other_default ? 1 : 0); bundle.putInt("screen_wifi_default", rule.screen_wifi_default ? 1 : 0); bundle.putInt("screen_other_default", rule.screen_other_default ? 1 : 0); bundle.putInt("roaming_default", rule.roaming_default ? 1 : 0); bundle.putInt("wifi_blocked", rule.wifi_blocked ? 1 : 0); bundle.putInt("other_blocked", rule.other_blocked ? 1 : 0); bundle.putInt("screen_wifi", rule.screen_wifi ? 1 : 0); bundle.putInt("screen_other", rule.screen_other ? 1 : 0); bundle.putInt("roaming", rule.roaming ? 1 : 0); bundle.putInt("apply", rule.apply ? 1 : 0); bundle.putInt("notify", rule.notify ? 1 : 0); submit(rule, bundle, context);//from w w w .j ava 2s. co m }
From source file:eu.faircode.netguard.ServiceJob.java
public static void submit(Rule rule, int version, int protocol, String daddr, int dport, int blocked, Context context) {//from w w w. j ava 2s . c o m PersistableBundle bundle = new PersistableBundle(); bundle.putString("type", "host"); bundle.putInt("version", version); bundle.putInt("protocol", protocol); bundle.putString("daddr", daddr); bundle.putInt("dport", dport); bundle.putInt("blocked", blocked); submit(rule, bundle, context); }
From source file:nuclei.task.TaskScheduler.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void onScheduleJobL(Context context) { JobInfo.Builder builder = new JobInfo.Builder(mBuilder.mTask.getTaskId(), new ComponentName(context, TaskJobService.class)); ArrayMap<String, Object> map = new ArrayMap<>(); mBuilder.mTask.serialize(map);/*from w w w . j ava 2 s. c o m*/ PersistableBundle extras = new PersistableBundle(); for (Map.Entry<String, Object> entry : map.entrySet()) { Object v = entry.getValue(); if (v == null) continue; if (v instanceof Integer) extras.putInt(entry.getKey(), (int) v); else if (v instanceof Double) extras.putDouble(entry.getKey(), (double) v); else if (v instanceof Long) extras.putLong(entry.getKey(), (long) v); else if (v instanceof String) extras.putString(entry.getKey(), (String) v); else if (v instanceof String[]) extras.putStringArray(entry.getKey(), (String[]) v); else if (v instanceof boolean[] && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) extras.putBooleanArray(entry.getKey(), (boolean[]) v); else if (v instanceof double[]) extras.putDoubleArray(entry.getKey(), (double[]) v); else if (v instanceof long[]) extras.putLongArray(entry.getKey(), (long[]) v); else if (v instanceof int[]) extras.putIntArray(entry.getKey(), (int[]) v); else throw new IllegalArgumentException("Invalid Type: " + entry.getKey()); } extras.putString(TASK_NAME, mBuilder.mTask.getClass().getName()); switch (mBuilder.mTaskType) { case TASK_ONE_OFF: if (mBuilder.mWindowStartDelaySecondsSet) builder.setMinimumLatency(mBuilder.mWindowStartDelaySeconds * 1000); if (mBuilder.mWindowEndDelaySecondsSet) builder.setOverrideDeadline(mBuilder.mWindowEndDelaySeconds * 1000); break; case TASK_PERIODIC: builder.setPeriodic(mBuilder.mPeriodInSeconds * 1000); break; default: throw new IllegalArgumentException(); } builder.setExtras(extras).setPersisted(mBuilder.mPersisted).setRequiresCharging(mBuilder.mRequiresCharging) .setRequiresDeviceIdle(mBuilder.mRequiresDeviceIdle); switch (mBuilder.mNetworkState) { case NETWORK_STATE_ANY: builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_NONE); break; case NETWORK_STATE_CONNECTED: builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY); break; case NETWORK_STATE_UNMETERED: builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); break; } switch (mBuilder.mBackoffPolicy) { case BACKOFF_POLICY_EXPONENTIAL: builder.setBackoffCriteria(mBuilder.mInitialBackoffMillis, JobInfo.BACKOFF_POLICY_EXPONENTIAL); break; case BACKOFF_POLICY_LINEAR: builder.setBackoffCriteria(mBuilder.mInitialBackoffMillis, JobInfo.BACKOFF_POLICY_LINEAR); break; } JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.schedule(builder.build()); }
From source file:com.afwsamples.testdpc.SetupManagementFragment.java
private void maybeLaunchProvisioning(String intentAction, int requestCode) { Activity activity = getActivity();// w w w. j a v a 2 s . c om Intent intent = new Intent(intentAction); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, DeviceAdminReceiver.getComponentName(getActivity())); } else { intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, getActivity().getPackageName()); } if (!maybeSpecifyNExtras(intent)) { // Unable to handle user-input - can't continue. return; } PersistableBundle adminExtras = new PersistableBundle(); maybeSpecifySyncAuthExtras(intent, adminExtras); maybePassAffiliationIds(intent, adminExtras); specifySkipUserConsent(intent); specifyKeepAccountMigrated(intent); specifySkipEncryption(intent); specifyDefaultDisclaimers(intent); if (adminExtras.size() > 0) { intent.putExtra(EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE, adminExtras); } if (intent.resolveActivity(activity.getPackageManager()) != null) { startActivityForResult(intent, requestCode); } else { Toast.makeText(activity, R.string.provisioning_not_supported, Toast.LENGTH_SHORT).show(); } }
From source file:com.android.contacts.DynamicShortcuts.java
@VisibleForTesting ShortcutInfo.Builder builderForContactShortcut(long id, String lookupKey, String displayName) { if (lookupKey == null || displayName == null) { return null; }/*from ww w.ja v a 2 s . c o m*/ final PersistableBundle extras = new PersistableBundle(); extras.putLong(Contacts._ID, id); extras.putInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_CONTACT_URI); final ShortcutInfo.Builder builder = new ShortcutInfo.Builder(mContext, lookupKey) .setIntent(ImplicitIntentsUtil.getIntentForQuickContactLauncherShortcut(mContext, Contacts.getLookupUri(id, lookupKey))) .setDisabledMessage(mContext.getString(R.string.dynamic_shortcut_disabled_message)) .setExtras(extras); setLabel(builder, displayName); return builder; }
From source file:com.android.contacts.DynamicShortcuts.java
@VisibleForTesting ShortcutInfo getActionShortcutInfo(String id, String label, Intent action, Icon icon) { if (id == null || label == null) { return null; }/*from w ww . ja v a2 s . c om*/ final PersistableBundle extras = new PersistableBundle(); extras.putInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_ACTION_URI); final ShortcutInfo.Builder builder = new ShortcutInfo.Builder(mContext, id).setIntent(action).setIcon(icon) .setExtras(extras) .setDisabledMessage(mContext.getString(R.string.dynamic_shortcut_disabled_message)); setLabel(builder, label); return builder.build(); }