android.os.PersistableBundle#putLong ( )源码实例Demo

下面列出了android.os.PersistableBundle#putLong ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: your-local-weather   文件: Location.java
public PersistableBundle getPersistableBundle() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        PersistableBundle persistableBundle = new PersistableBundle();
        persistableBundle.putLong("id", id);
        persistableBundle.putDouble("latitude", latitude);
        persistableBundle.putDouble("longitude", longitude);
        persistableBundle.putInt("orderId", orderId);
        persistableBundle.putString("locale", localeAbbrev);
        persistableBundle.putString("nickname", nickname);
        persistableBundle.putDouble("accuracy", new Double(accuracy));
        persistableBundle.putString("locationSource", locationSource);
        persistableBundle.putLong("lastLocationUpdate", lastLocationUpdate);
        persistableBundle.putPersistableBundle("address", PersistableBundleBuilder.fromAddress(address));
        return persistableBundle;
    } else {
        return null;
    }
}
 
public static void scheduleAddWatchNextRequest(Context context, ClipData clipData) {
    JobScheduler scheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE);

    PersistableBundle bundle = new PersistableBundle();
    bundle.putString(ID_KEY, clipData.getClipId());
    bundle.putString(CONTENT_ID_KEY, clipData.getContentId());
    bundle.putLong(DURATION_KEY, clipData.getDuration());
    bundle.putLong(PROGRESS_KEY, clipData.getProgress());
    bundle.putString(TITLE_KEY, clipData.getTitle());
    bundle.putString(DESCRIPTION_KEY, clipData.getDescription());
    bundle.putString(CARD_IMAGE_URL_KEY, clipData.getCardImageUrl());

    scheduler.schedule(new JobInfo.Builder(1,
            new ComponentName(context, AddWatchNextService.class))
            .setExtras(bundle)
            .build());
}
 
源代码3 项目: xipl   文件: 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.
 * @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");
    }
}
 
源代码4 项目: xipl   文件: EpgSyncJobService.java
/**
 * Manually requests a job to run now.
 *
 * <p>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.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");
    }
}
 
源代码5 项目: mimi-reader   文件: RefreshScheduler.java
private void scheduleJob(ThreadInfo threadInfo, long nextRunTime) {
    long delay = nextRunTime - System.currentTimeMillis();
    PersistableBundle bundle = new PersistableBundle();
    bundle.putLong(THREAD_ID_EXTRA, threadInfo.threadId);
    bundle.putString(BOARD_NAME_EXTRA, threadInfo.boardName);
    bundle.putString(BOARD_TITLE_EXTRA, threadInfo.boardTitle);
    bundle.putInt(WATCHED_EXTRA, threadInfo.watched ? 1 : 0);
    bundle.putLong(LAST_REFRESH_TIME_EXTRA, threadInfo.refreshTimestamp);
    bundle.putInt(RESULT_KEY, RESULT_SCHEDULED);
    bundle.putInt(BACKGROUNDED_KEY, backgrounded ? 1 : 0);

    ComponentName serviceComponent = new ComponentName(context, RefreshJobService.class);
    JobInfo jobInfo = new JobInfo.Builder(JOB_ID, serviceComponent)
            .setMinimumLatency(delay)
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
            .setRequiresCharging(false)
            .setExtras(bundle)
            .build();
    refreshScheduler.schedule(jobInfo);
}
 
源代码6 项目: CumulusTV   文件: CumulusJobService.java
@Deprecated
public static void requestImmediateSync1(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 >= 22) {
        persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        persistableBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    }
    persistableBundle.putString(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, inputId);
    persistableBundle.putLong("bundle_key_sync_period", syncDuration);
    JobInfo.Builder builder = new JobInfo.Builder(1, jobServiceComponent);
    JobInfo jobInfo = builder
            .setExtras(persistableBundle)
            .setOverrideDeadline(1000)
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
            .build();
    scheduleJob(context, jobInfo);
    Log.d(TAG, "Single job scheduled");
}
 
/**
 * 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.
 * @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");
    }
}
 
/**
 * Manually requests a job to run now.
 *
 * <p>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.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");
    }
}
 
源代码9 项目: your-local-weather   文件: LicenseKey.java
public PersistableBundle getPersistableBundle() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        PersistableBundle persistableBundle = new PersistableBundle();
        persistableBundle.putLong("id", id);
        persistableBundle.putString("requestUri", requestUri);
        persistableBundle.putString("initialLicense", initialLicense);
        persistableBundle.putString("token", token);
        persistableBundle.putLong("lastCallTimeInMs", lastCallTimeInMs);
        return persistableBundle;
    } else {
        return null;
    }
}
 
源代码10 项目: your-local-weather   文件: VoiceSettingParameter.java
public PersistableBundle getPersistableBundle() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        PersistableBundle persistableBundle = new PersistableBundle();
        persistableBundle.putLong("id", id);
        persistableBundle.putLong("voiceSettingId", voiceSettingId);
        persistableBundle.putInt("paramTypeId", paramTypeId);
        persistableBundle.putInt("paramBooleanValue", mapBooleanToInt(paramBooleanValue));
        persistableBundle.putLong("paramLongValue", paramLongValue);
        persistableBundle.putString("paramStringValue", paramStringValue);
        return persistableBundle;
    } else {
        return null;
    }
}
 
源代码11 项目: BackPackTrackII   文件: Util.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static PersistableBundle getPersistableBundle(Bundle bundle) {
    PersistableBundle result = new PersistableBundle();
    for (String key : bundle.keySet())
        if (bundle.get(key) instanceof Boolean)
            result.putBoolean(key, bundle.getBoolean(key));
        else if (bundle.get(key) instanceof Integer)
            result.putInt(key, bundle.getInt(key));
        else if (bundle.get(key) instanceof Long)
            result.putLong(key, bundle.getLong(key));
        else if (bundle.get(key) instanceof String || bundle.get(key) == null)
            result.putString(key, bundle.getString(key));
    return result;
}
 
/**
 * Copy all entries in the {@link Bundle} that can be part of a {@link PersistableBundle}.
 *
 * @param bundle the {@link Bundle} to convert.
 * @return a result object contain the resulting {@link PersistableBundle} and whether any of
 *         the keys failed.
 */
static Result convert(Bundle bundle) {
    PersistableBundle persistableBundle = new PersistableBundle();
    Set<String> failedKeys = new HashSet<>();
    for (String key : bundle.keySet()) {
        Object obj = bundle.get(key);
        if (obj == null) {
            persistableBundle.putString(key, null);
        } else if (obj instanceof Boolean) {
            persistableBundle.putBoolean(key, (Boolean) obj);
        } else if (obj instanceof boolean[]) {
            persistableBundle.putBooleanArray(key, (boolean[]) obj);
        } else if (obj instanceof Double) {
            persistableBundle.putDouble(key, (Double) obj);
        } else if (obj instanceof double[]) {
            persistableBundle.putDoubleArray(key, (double[]) obj);
        } else if (obj instanceof Integer) {
            persistableBundle.putInt(key, (Integer) obj);
        } else if (obj instanceof int[]) {
            persistableBundle.putIntArray(key, (int[]) obj);
        } else if (obj instanceof Long) {
            persistableBundle.putLong(key, (Long) obj);
        } else if (obj instanceof long[]) {
            persistableBundle.putLongArray(key, (long[]) obj);
        } else if (obj instanceof String) {
            persistableBundle.putString(key, (String) obj);
        } else if (obj instanceof String[]) {
            persistableBundle.putStringArray(key, (String[]) obj);
        } else {
            failedKeys.add(key);
        }
    }
    return new Result(persistableBundle, failedKeys);
}
 
源代码13 项目: android-JobScheduler   文件: MainActivity.java
/**
 * Executed when user clicks on SCHEDULE JOB.
 */
public void scheduleJob(View v) {
    JobInfo.Builder builder = new JobInfo.Builder(mJobId++, mServiceComponent);

    String delay = mDelayEditText.getText().toString();
    if (!TextUtils.isEmpty(delay)) {
        builder.setMinimumLatency(Long.valueOf(delay) * 1000);
    }
    String deadline = mDeadlineEditText.getText().toString();
    if (!TextUtils.isEmpty(deadline)) {
        builder.setOverrideDeadline(Long.valueOf(deadline) * 1000);
    }
    boolean requiresUnmetered = mWiFiConnectivityRadioButton.isChecked();
    boolean requiresAnyConnectivity = mAnyConnectivityRadioButton.isChecked();
    if (requiresUnmetered) {
        builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
    } else if (requiresAnyConnectivity) {
        builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
    }
    builder.setRequiresDeviceIdle(mRequiresIdleCheckbox.isChecked());
    builder.setRequiresCharging(mRequiresChargingCheckBox.isChecked());

    // Extras, work duration.
    PersistableBundle extras = new PersistableBundle();
    String workDuration = mDurationTimeEditText.getText().toString();
    if (TextUtils.isEmpty(workDuration)) {
        workDuration = "1";
    }
    extras.putLong(WORK_DURATION_KEY, Long.valueOf(workDuration) * 1000);

    builder.setExtras(extras);

    // Schedule job
    Log.d(TAG, "Scheduling job");
    JobScheduler tm = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
    tm.schedule(builder.build());
}
 
源代码14 项目: android_9.0.0_r45   文件: SyncOperation.java
/**
 * All fields are stored in a corresponding key in the persistable bundle.
 *
 * {@link #extras} is a Bundle and can contain parcelable objects. But only the type Account
 * is allowed {@link ContentResolver#validateSyncExtrasBundle(Bundle)} that can't be stored in
 * a PersistableBundle. For every value of type Account with key 'key', we store a
 * PersistableBundle containing account information at key 'ACCOUNT:key'. The Account object
 * can be reconstructed using this.
 *
 * We put a flag with key 'SyncManagerJob', to identify while reconstructing a sync operation
 * from a bundle whether the bundle actually contains information about a sync.
 * @return A persistable bundle containing all information to re-construct the sync operation.
 */
PersistableBundle toJobInfoExtras() {
    // This will be passed as extras bundle to a JobScheduler job.
    PersistableBundle jobInfoExtras = new PersistableBundle();

    PersistableBundle syncExtrasBundle = new PersistableBundle();
    for (String key: extras.keySet()) {
        Object value = extras.get(key);
        if (value instanceof Account) {
            Account account = (Account) value;
            PersistableBundle accountBundle = new PersistableBundle();
            accountBundle.putString("accountName", account.name);
            accountBundle.putString("accountType", account.type);
            // This is stored in jobInfoExtras so that we don't override a user specified
            // sync extra with the same key.
            jobInfoExtras.putPersistableBundle("ACCOUNT:" + key, accountBundle);
        } else if (value instanceof Long) {
            syncExtrasBundle.putLong(key, (Long) value);
        } else if (value instanceof Integer) {
            syncExtrasBundle.putInt(key, (Integer) value);
        } else if (value instanceof Boolean) {
            syncExtrasBundle.putBoolean(key, (Boolean) value);
        } else if (value instanceof Float) {
            syncExtrasBundle.putDouble(key, (double) (float) value);
        } else if (value instanceof Double) {
            syncExtrasBundle.putDouble(key, (Double) value);
        } else if (value instanceof String) {
            syncExtrasBundle.putString(key, (String) value);
        } else if (value == null) {
            syncExtrasBundle.putString(key, null);
        } else {
            Slog.e(TAG, "Unknown extra type.");
        }
    }
    jobInfoExtras.putPersistableBundle("syncExtras", syncExtrasBundle);

    jobInfoExtras.putBoolean("SyncManagerJob", true);

    jobInfoExtras.putString("provider", target.provider);
    jobInfoExtras.putString("accountName", target.account.name);
    jobInfoExtras.putString("accountType", target.account.type);
    jobInfoExtras.putInt("userId", target.userId);
    jobInfoExtras.putInt("owningUid", owningUid);
    jobInfoExtras.putString("owningPackage", owningPackage);
    jobInfoExtras.putInt("reason", reason);
    jobInfoExtras.putInt("source", syncSource);
    jobInfoExtras.putBoolean("allowParallelSyncs", allowParallelSyncs);
    jobInfoExtras.putInt("jobId", jobId);
    jobInfoExtras.putBoolean("isPeriodic", isPeriodic);
    jobInfoExtras.putInt("sourcePeriodicId", sourcePeriodicId);
    jobInfoExtras.putLong("periodMillis", periodMillis);
    jobInfoExtras.putLong("flexMillis", flexMillis);
    jobInfoExtras.putLong("expectedRuntime", expectedRuntime);
    jobInfoExtras.putInt("retries", retries);
    jobInfoExtras.putInt("syncExemptionFlag", syncExemptionFlag);
    return jobInfoExtras;
}
 
private int runSuspend(boolean suspendedState) {
    final PrintWriter pw = getOutPrintWriter();
    int userId = UserHandle.USER_SYSTEM;
    String dialogMessage = null;
    final PersistableBundle appExtras = new PersistableBundle();
    final PersistableBundle launcherExtras = new PersistableBundle();
    String opt;
    while ((opt = getNextOption()) != null) {
        switch (opt) {
            case "--user":
                userId = UserHandle.parseUserArg(getNextArgRequired());
                break;
            case "--dialogMessage":
                dialogMessage = getNextArgRequired();
                break;
            case "--ael":
            case "--aes":
            case "--aed":
            case "--lel":
            case "--les":
            case "--led":
                final String key = getNextArgRequired();
                final String val = getNextArgRequired();
                if (!suspendedState) {
                    break;
                }
                final PersistableBundle bundleToInsert =
                        opt.startsWith("--a") ? appExtras : launcherExtras;
                switch (opt.charAt(4)) {
                    case 'l':
                        bundleToInsert.putLong(key, Long.valueOf(val));
                        break;
                    case 'd':
                        bundleToInsert.putDouble(key, Double.valueOf(val));
                        break;
                    case 's':
                        bundleToInsert.putString(key, val);
                        break;
                }
                break;
            default:
                pw.println("Error: Unknown option: " + opt);
                return 1;
        }
    }

    final String packageName = getNextArg();
    if (packageName == null) {
        pw.println("Error: package name not specified");
        return 1;
    }
    final String callingPackage =
            (Binder.getCallingUid() == Process.ROOT_UID) ? "root" : "com.android.shell";
    try {
        mInterface.setPackagesSuspendedAsUser(new String[]{packageName}, suspendedState,
                appExtras, launcherExtras, dialogMessage, callingPackage, userId);
        pw.println("Package " + packageName + " new suspended state: "
                + mInterface.isPackageSuspendedForUser(packageName, userId));
        return 0;
    } catch (RemoteException | IllegalArgumentException e) {
        pw.println(e.toString());
        return 1;
    }
}
 
源代码16 项目: user-interface-samples   文件: ShortcutHelper.java
private ShortcutInfo.Builder setExtras(ShortcutInfo.Builder b) {
    final PersistableBundle extras = new PersistableBundle();
    extras.putLong(EXTRA_LAST_REFRESH, System.currentTimeMillis());
    b.setExtras(extras);
    return b;
}
 
源代码17 项目: android-AppShortcuts   文件: ShortcutHelper.java
private ShortcutInfo.Builder setExtras(ShortcutInfo.Builder b) {
    final PersistableBundle extras = new PersistableBundle();
    extras.putLong(EXTRA_LAST_REFRESH, System.currentTimeMillis());
    b.setExtras(extras);
    return b;
}
 
源代码18 项目: android-sdk   文件: ServiceScheduler.java
private void setRepeating(long interval, PendingIntent pendingIntent, Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        int jobId = getJobId(intent);
        if (jobId == -1) {
            logger.error("Problem getting scheduled job id");
            return;
        }

        if (isScheduled(context, jobId)) {
            logger.info("Job already started");
            return;
        }

        JobScheduler jobScheduler = (JobScheduler)
                context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        JobInfo.Builder builder = new JobInfo.Builder(jobId,
                new ComponentName(context.getApplicationContext(),
                        ScheduledJobService.class.getName()));
        builder.setPeriodic(interval, interval);
        builder.setPersisted(true);
        // we are only doing repeating on datafile service. it is a prefetch.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            builder.setPrefetch(true);
        }
        builder.setBackoffCriteria(JobInfo.DEFAULT_INITIAL_BACKOFF_MILLIS, JobInfo.BACKOFF_POLICY_LINEAR);

        intent.putExtra(JobWorkService.INTENT_EXTRA_JWS_PERIODIC, interval);
        PersistableBundle persistableBundle = new PersistableBundle();

        for (String key : intent.getExtras().keySet()) {
            Object object = intent.getExtras().get(key);
            switch (object.getClass().getSimpleName()) {
                case "String":
                    persistableBundle.putString(key, (String) object);
                    break;
                case "long":
                case "Long":
                    persistableBundle.putLong(key, (Long) object);
                    break;
                default:
                    logger.info("No conversion for {}", object.getClass().getSimpleName());
            }
        }

        persistableBundle.putString(ScheduledJobService.INTENT_EXTRA_COMPONENT_NAME, intent.getComponent().getClassName());

        builder.setExtras(persistableBundle);

        try {
            if (jobScheduler.schedule(builder.build()) != RESULT_SUCCESS) {
                logger.error("ServiceScheduler", "Some error while scheduling the job");
            }
        }
        catch (Exception e) {
            logger.error(String.format("Problem scheduling job %s", intent.getComponent().toShortString()), e);
        }
    }
    else {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, interval, interval, pendingIntent);
    }
}