List of usage examples for android.os PersistableBundle putString
public void putString(@Nullable String key, @Nullable String value)
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 .j a va 2 s. 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 w ww. j a va 2 s . co 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:eu.faircode.netguard.ServiceJob.java
public static void submit(Rule rule, int version, int protocol, String daddr, int dport, int blocked, Context context) {/*from ww w .j a v a 2 s .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: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);// w w w . j a va2s . c o m }
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); }/* www. ja va 2s . com*/ } return persistableBundle; }
From source file:com.google.android.media.tv.companionlibrary.EpgSyncJobService.java
/** * Initializes a job that will periodically update the app's channels and programs. * * @param context Application's context. * @param inputId Component name for the app's TvInputService. This can be received through an * Intent extra parameter {@link TvInputInfo#EXTRA_INPUT_ID}. * @param jobServiceComponent The {@link EpgSyncJobService} component name that will run. * @param fullSyncPeriod The period between when the job will run a full background sync in * milliseconds./*from w ww .ja v a 2s . co m*/ * @param syncDuration The duration of EPG content to fetch in milliseconds. For a manual sync, * this should be relatively short. For a background sync this should be long. */ public static void setUpPeriodicSync(Context context, String inputId, ComponentName jobServiceComponent, long fullSyncPeriod, long syncDuration) { if (jobServiceComponent.getClass().isAssignableFrom(EpgSyncJobService.class)) { throw new IllegalArgumentException("This class does not extend EpgSyncJobService"); } PersistableBundle persistableBundle = new PersistableBundle(); persistableBundle.putString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, inputId); persistableBundle.putLong(EpgSyncJobService.BUNDLE_KEY_SYNC_PERIOD, syncDuration); JobInfo.Builder builder = new JobInfo.Builder(PERIODIC_SYNC_JOB_ID, jobServiceComponent); JobInfo jobInfo = builder.setExtras(persistableBundle).setPeriodic(fullSyncPeriod).setPersisted(true) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build(); scheduleJob(context, jobInfo); if (DEBUG) { Log.d(TAG, "Job has been scheduled for every " + fullSyncPeriod + "ms"); } }
From source file:com.google.android.media.tv.companionlibrary.EpgSyncJobService.java
/** * Manually requests a job to run now.//w w w .ja v a2 s . c o m * * To check the current status of the sync, register a {@link android.content.BroadcastReceiver} * with an {@link android.content.IntentFilter} which checks for the action * {@link #ACTION_SYNC_STATUS_CHANGED}. * <p /> * The sync status is an extra parameter in the {@link Intent} with key * {@link #SYNC_STATUS}. The sync status is either {@link #SYNC_STARTED} or * {@link #SYNC_FINISHED}. * <p /> * Check that the value of {@link #BUNDLE_KEY_INPUT_ID} matches your * {@link android.media.tv.TvInputService}. If you're calling this from your setup activity, * you can get the extra parameter {@link TvInputInfo#EXTRA_INPUT_ID}. * <p /> * @param context Application's context. * @param inputId Component name for the app's TvInputService. This can be received through an * Intent extra parameter {@link TvInputInfo#EXTRA_INPUT_ID}. * @param syncDuration The duration of EPG content to fetch in milliseconds. For a manual sync, * this should be relatively short. For a background sync this should be long. * @param jobServiceComponent The {@link EpgSyncJobService} class that will run. */ public static void requestImmediateSync(Context context, String inputId, long syncDuration, ComponentName jobServiceComponent) { if (jobServiceComponent.getClass().isAssignableFrom(EpgSyncJobService.class)) { throw new IllegalArgumentException("This class does not extend EpgSyncJobService"); } PersistableBundle persistableBundle = new PersistableBundle(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); } persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); persistableBundle.putString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, inputId); persistableBundle.putLong(EpgSyncJobService.BUNDLE_KEY_SYNC_PERIOD, syncDuration); JobInfo.Builder builder = new JobInfo.Builder(REQUEST_SYNC_JOB_ID, jobServiceComponent); JobInfo jobInfo = builder.setExtras(persistableBundle) .setOverrideDeadline(EpgSyncJobService.OVERRIDE_DEADLINE_MILLIS) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build(); scheduleJob(context, jobInfo); if (DEBUG) { Log.d(TAG, "Single job scheduled"); } }
From source file:eu.faircode.netguard.ServiceJob.java
private static void submit(Rule rule, PersistableBundle bundle, Context context) { PackageManager pm = context.getPackageManager(); JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); // Get english application label String label = null;/*from ww w .j a va2 s . c om*/ try { Configuration config = new Configuration(); config.setLocale(new Locale("en")); Resources res = pm.getResourcesForApplication(rule.info.packageName); res.updateConfiguration(config, res.getDisplayMetrics()); label = res.getString(rule.info.applicationInfo.labelRes); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); CharSequence cs = rule.info.applicationInfo.loadLabel(pm); if (cs != null) label = cs.toString(); } // Add application data bundle.putInt("uid", rule.info.applicationInfo.uid); bundle.putString("package", rule.info.packageName); bundle.putInt("version_code", rule.info.versionCode); bundle.putString("version_name", rule.info.versionName); bundle.putString("label", label); bundle.putInt("system", rule.system ? 1 : 0); try { bundle.putString("installer", pm.getInstallerPackageName(rule.info.packageName)); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); bundle.putString("installer", null); } // Cancel overlapping jobs for (JobInfo pending : scheduler.getAllPendingJobs()) { String type = pending.getExtras().getString("type"); if (type != null && type.equals(bundle.getString("type"))) { if (type.equals("rule")) { int uid = pending.getExtras().getInt("uid"); if (uid == bundle.getInt("uid")) { Log.i(TAG, "Canceling id=" + pending.getId()); scheduler.cancel(pending.getId()); } } else if (type.equals("host")) { int uid = pending.getExtras().getInt("uid"); int version = pending.getExtras().getInt("version"); int protocol = pending.getExtras().getInt("protocol"); String daddr = pending.getExtras().getString("daddr"); int dport = pending.getExtras().getInt("dport"); if (uid == bundle.getInt("uid") && version == bundle.getInt("version") && protocol == bundle.getInt("protocol") && daddr != null && daddr.equals(bundle.getString("daddr")) && dport == bundle.getInt("dport")) { Log.i(TAG, "Canceling id=" + pending.getId()); scheduler.cancel(pending.getId()); } } } } // Schedule job ComponentName serviceName = new ComponentName(context, ServiceJob.class); JobInfo job = new JobInfo.Builder(++id, serviceName).setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED) .setMinimumLatency(Util.isDebuggable(context) ? 10 * 1000 : 60 * 1000).setExtras(bundle) .setPersisted(true).build(); if (scheduler.schedule(job) == JobScheduler.RESULT_SUCCESS) Log.i(TAG, "Scheduled job=" + job.getId() + " success"); else Log.e(TAG, "Scheduled job=" + job.getId() + " failed"); }
From source file:com.example.android.dragsource.DragSourceFragment.java
private void setUpDraggableImage(ImageView imageView, final Uri imageUri) { // Set up a listener that starts the drag and drop event with flags and extra data. DragStartHelper.OnDragStartListener listener = new DragStartHelper.OnDragStartListener() { @Override//from ww w . j a va 2s.co m public boolean onDragStart(View view, final DragStartHelper helper) { Log.d(TAG, "Drag start event received from helper."); // Use a DragShadowBuilder View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view) { @Override public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { super.onProvideShadowMetrics(shadowSize, shadowTouchPoint); // Notify the DragStartHelper of point where the view was touched. helper.getTouchPosition(shadowTouchPoint); Log.d(TAG, "View was touched at: " + shadowTouchPoint); } }; // Set up the flags for the drag event. // Enable drag and drop across apps (global) // and require read permissions for this URI. int flags = View.DRAG_FLAG_GLOBAL | View.DRAG_FLAG_GLOBAL_URI_READ; // Add an optional clip description that that contains an extra String that is // read out by the target app. final ClipDescription clipDescription = new ClipDescription("", new String[] { getContext().getContentResolver().getType(imageUri) }); // Extras are stored within a PersistableBundle. PersistableBundle extras = new PersistableBundle(1); // Add a String that the target app will display. extras.putString(EXTRA_IMAGE_INFO, "Drag Started at " + new Date()); clipDescription.setExtras(extras); // The ClipData object describes the object that is being dragged and dropped. final ClipData clipData = new ClipData(clipDescription, new ClipData.Item(imageUri)); Log.d(TAG, "Created ClipDescription. Starting drag and drop."); // Start the drag and drop event. return view.startDragAndDrop(clipData, shadowBuilder, null, flags); } }; // Use the DragStartHelper to detect drag and drop events and use the OnDragStartListener // defined above to start the event when it has been detected. DragStartHelper helper = new DragStartHelper(imageView, listener); helper.attach(); Log.d(TAG, "DragStartHelper attached to view."); }
From source file:com.owncloud.android.files.services.TransferRequester.java
/** * Schedule a future transfer of an upload, to be done when a connection via an unmetered network (free Wifi) * is available./* w w w . j a va 2 s . c o m*/ * * @param context Caller {@link Context}. * @param scheduledRetryService Class of the appropriate retry service, either to retry downloads * or to retry uploads. * @param jobId Identifier to set to the retry job. * @param accountName Local name of the OC account where the upload will be retried. * @param remotePath Full path of the file to upload, relative to root of the OC account. */ private boolean scheduleTransfer(Context context, Class<?> scheduledRetryService, int jobId, String accountName, String remotePath) { // JobShceduler requires Android >= 5.0 ; do not remove this protection while minSdkVersion is lower if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return false; } ComponentName serviceComponent = new ComponentName(context, scheduledRetryService); JobInfo.Builder builder = new JobInfo.Builder(jobId, serviceComponent); int networkType = getRequiredNetworkType(context, accountName, remotePath); // require network type (Wifi or Wifi and cellular) builder.setRequiredNetworkType(networkType); // Persist job and prevent it from being deleted after a device restart builder.setPersisted(true); // Extra data PersistableBundle extras = new PersistableBundle(); extras.putString(Extras.EXTRA_REMOTE_PATH, remotePath); extras.putString(Extras.EXTRA_ACCOUNT_NAME, accountName); builder.setExtras(extras); JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.schedule(builder.build()); return true; }