本文整理汇总了Java中com.evernote.android.job.JobRequest类的典型用法代码示例。如果您正苦于以下问题:Java JobRequest类的具体用法?Java JobRequest怎么用?Java JobRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JobRequest类属于com.evernote.android.job包,在下文中一共展示了JobRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPeriodic
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
@Override
public void createPeriodic() {
for (int i = 0; i < 10; i++) {
JobRequest.Builder builder = new JobRequest.Builder("tag")
.setPeriodic(TimeUnit.MINUTES.toMillis(1))
.setRequiresCharging(random())
.setRequiresDeviceIdle(random())
.setRequiredNetworkType(random() ? JobRequest.NetworkType.ANY : JobRequest.NetworkType.CONNECTED)
.setRequirementsEnforced(random());
if (random()) {
PersistableBundleCompat extras = new PersistableBundleCompat();
extras.putString("key", "Hello world");
builder.setExtras(extras);
}
builder.build().schedule();
}
}
示例2: initialize
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
@Override
public void initialize() {
Log.d(TAG, "Initializing");
super.initialize();
// Read in an existing scheduled job if there is one
Set<JobRequest> jobRequests = JobManager.instance().getAllJobRequests();
if (jobRequests.size() > 1) {
Log.w(TAG, "Found " + jobRequests.size() + " scheduled jobs, expecting 0 or 1");
}
if (!jobRequests.isEmpty()) {
mJobRequest = jobRequests.iterator().next();
}
// Hook into lifecycle events so we can tell when the application is foregrounded
ReactApplicationContext context = getReactApplicationContext();
context.addLifecycleEventListener(this);
}
示例3: scheduleJobImmediately
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
public static void scheduleJobImmediately(boolean byUser, Calendar start, Calendar end) {
PersistableBundleCompat extras = new PersistableBundleCompat();
extras.putBoolean(ARG_INITIATED_BY_USER, byUser);
if (start != null && end != null) {
extras.putString(SyncJob.ARG_START_DATE, new SimpleDateFormat("yyyy-MM-dd", Locale.GERMANY).format(start.getTime()));
extras.putString(SyncJob.ARG_END_DATE, new SimpleDateFormat("yyyy-MM-dd", Locale.GERMANY).format(end.getTime()));
}
new JobRequest.Builder(TAG).startNow()
.setExtras(extras)
.build()
.schedule();
}
示例4: plantOneOff
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
@Override
public void plantOneOff(JobRequest request) {
long startMs = Common.getStartMs(request);
long endMs = Common.getEndMs(request, true);
JobInfo jobInfo = createBuilderOneOff(createBaseBuilder(request, true), startMs, endMs).build();
int scheduleResult = schedule(jobInfo);
if (scheduleResult == ERROR_BOOT_PERMISSION) {
jobInfo = createBuilderOneOff(createBaseBuilder(request, false), startMs, endMs).build();
scheduleResult = schedule(jobInfo);
}
mCat.d("Schedule one-off jobInfo %s, %s, start %s, end %s (from now), reschedule count %d", scheduleResultToString(scheduleResult),
request, JobUtil.timeToString(startMs), JobUtil.timeToString(endMs), Common.getRescheduleCount(request));
}
示例5: plantPeriodic
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
@Override
public void plantPeriodic(JobRequest request) {
long intervalMs = request.getIntervalMs();
long flexMs = request.getFlexMs();
JobInfo jobInfo = createBuilderPeriodic(createBaseBuilder(request, true), intervalMs, flexMs).build();
int scheduleResult = schedule(jobInfo);
if (scheduleResult == ERROR_BOOT_PERMISSION) {
jobInfo = createBuilderPeriodic(createBaseBuilder(request, false), intervalMs, flexMs).build();
scheduleResult = schedule(jobInfo);
}
mCat.d("Schedule periodic jobInfo %s, %s, interval %s, flex %s", scheduleResultToString(scheduleResult),
request, JobUtil.timeToString(intervalMs), JobUtil.timeToString(flexMs));
}
示例6: plantPeriodicFlexSupport
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
@Override
public void plantPeriodicFlexSupport(JobRequest request) {
long startMs = Common.getStartMsSupportFlex(request);
long endMs = Common.getEndMsSupportFlex(request);
JobInfo jobInfo = createBuilderOneOff(createBaseBuilder(request, true), startMs, endMs).build();
int scheduleResult = schedule(jobInfo);
if (scheduleResult == ERROR_BOOT_PERMISSION) {
jobInfo = createBuilderOneOff(createBaseBuilder(request, false), startMs, endMs).build();
scheduleResult = schedule(jobInfo);
}
mCat.d("Schedule periodic (flex support) jobInfo %s, %s, start %s, end %s, flex %s", scheduleResultToString(scheduleResult),
request, JobUtil.timeToString(startMs), JobUtil.timeToString(endMs), JobUtil.timeToString(request.getFlexMs()));
}
示例7: isPlatformJobScheduled
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
@Override
public boolean isPlatformJobScheduled(JobRequest request) {
List<JobInfo> pendingJobs;
try {
pendingJobs = getJobScheduler().getAllPendingJobs();
} catch (Exception e) {
// it's possible that this throws an exception, see https://gist.github.com/vRallev/a59947dd3932d2642641
mCat.e(e);
return false;
}
//noinspection ConstantConditions
if (pendingJobs == null || pendingJobs.isEmpty()) {
return false;
}
for (JobInfo info : pendingJobs) {
if (isJobInfoScheduled(info, request)) {
return true;
}
}
return false;
}
示例8: convertNetworkType
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
protected int convertNetworkType(@NonNull JobRequest.NetworkType networkType) {
switch (networkType) {
case ANY:
return JobInfo.NETWORK_TYPE_NONE;
case CONNECTED:
return JobInfo.NETWORK_TYPE_ANY;
case UNMETERED:
return JobInfo.NETWORK_TYPE_UNMETERED;
case NOT_ROAMING:
return JobInfo.NETWORK_TYPE_UNMETERED; // use unmetered here, is overwritten in v24
case METERED:
return JobInfo.NETWORK_TYPE_ANY; // use any here as fallback
default:
throw new IllegalStateException("not implemented");
}
}
示例9: startWithTransientBundle
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
public static boolean startWithTransientBundle(@NonNull Context context, @NonNull JobRequest request) {
// transientExtras are not necessary in this case
Intent intent = PlatformAlarmServiceExact.createIntent(context, request.getJobId(), null);
PendingIntent pendingIntent = PendingIntent.getService(context, request.getJobId(), intent, PendingIntent.FLAG_NO_CREATE);
if (pendingIntent == null) {
return false;
}
try {
CAT.i("Delegating transient job %s to API 14", request);
pendingIntent.send();
} catch (PendingIntent.CanceledException e) {
CAT.e(e);
return false;
}
if (!request.isPeriodic()) {
cancel(context, request.getJobId(), pendingIntent);
}
return true;
}
示例10: plantOneOff
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
@Override
public void plantOneOff(JobRequest request) {
PendingIntent pendingIntent = getPendingIntent(request, false);
AlarmManager alarmManager = getAlarmManager();
if (alarmManager == null) {
return;
}
try {
if (request.isExact()) {
if (request.getStartMs() == 1 && request.getFailureCount() <= 0) {
// this job should start immediately
PlatformAlarmService.start(mContext, request.getJobId(), request.getTransientExtras());
} else {
plantOneOffExact(request, alarmManager, pendingIntent);
}
} else {
plantOneOffInexact(request, alarmManager, pendingIntent);
}
} catch (Exception e) {
// https://gist.github.com/vRallev/621b0b76a14ddde8691c
mCat.e(e);
}
}
示例11: plantPeriodicFlexSupport
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
@Override
public void plantPeriodicFlexSupport(JobRequest request) {
PendingIntent pendingIntent = getPendingIntent(request, false);
AlarmManager alarmManager = getAlarmManager();
if (alarmManager == null) {
return;
}
try {
plantOneOffFlexSupport(request, alarmManager, pendingIntent);
} catch (Exception e) {
// https://gist.github.com/vRallev/621b0b76a14ddde8691c
mCat.e(e);
}
}
示例12: runJob
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
static void runJob(@Nullable Intent intent, @NonNull Service service, @NonNull JobCat cat) {
if (intent == null) {
cat.i("Delivered intent is null");
return;
}
int jobId = intent.getIntExtra(PlatformAlarmReceiver.EXTRA_JOB_ID, -1);
Bundle transientExtras = intent.getBundleExtra(PlatformAlarmReceiver.EXTRA_TRANSIENT_EXTRAS);
final JobProxy.Common common = new JobProxy.Common(service, cat, jobId);
// create the JobManager. Seeing sometimes exceptions, that it wasn't created, yet.
final JobRequest request = common.getPendingRequest(true, true);
if (request != null) {
common.executeJobRequest(request, transientExtras);
}
}
示例13: getNetworkType
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
/**
* Checks the network condition of the device and returns the best type. If the device
* is connected to a WiFi and mobile network at the same time, then it would assume
* that the connection is unmetered because of the WiFi connection.
*
* @param context Any context, e.g. the application context.
* @return The current network type of the device.
*/
@NonNull
public static JobRequest.NetworkType getNetworkType(@NonNull Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
return JobRequest.NetworkType.ANY;
}
boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(connectivityManager);
if (!metered) {
return JobRequest.NetworkType.UNMETERED;
}
if (networkInfo.isRoaming()) {
return JobRequest.NetworkType.CONNECTED;
} else {
return JobRequest.NetworkType.NOT_ROAMING;
}
}
示例14: onRunTask
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
@Override
public int onRunTask(TaskParams taskParams) {
int jobId = Integer.parseInt(taskParams.getTag());
JobProxy.Common common = new JobProxy.Common(this, CAT, jobId);
JobRequest request = common.getPendingRequest(true, true);
if (request == null) {
return GcmNetworkManager.RESULT_FAILURE;
}
Job.Result result = common.executeJobRequest(request, taskParams.getExtras());
if (Job.Result.SUCCESS.equals(result)) {
return GcmNetworkManager.RESULT_SUCCESS;
} else {
return GcmNetworkManager.RESULT_FAILURE;
}
}
示例15: plantOneOff
import com.evernote.android.job.JobRequest; //导入依赖的package包/类
@Override
public void plantOneOff(JobRequest request) {
long startMs = Common.getStartMs(request);
long startSeconds = startMs / 1_000;
long endMs = Common.getEndMs(request);
long endSeconds = Math.max(endMs / 1_000, startSeconds + 1); // endSeconds must be greater than startSeconds
OneoffTask task = prepareBuilder(new OneoffTask.Builder(), request)
.setExecutionWindow(startSeconds, endSeconds)
.build();
mGcmNetworkManager.schedule(task);
CAT.d("Scheduled OneoffTask, %s, start %s, end %s (from now), reschedule count %d", request, JobUtil.timeToString(startMs),
JobUtil.timeToString(endMs), Common.getRescheduleCount(request));
}