diff options
author | Dianne Hackborn <hackbod@google.com> | 2016-06-01 19:29:41 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-06-01 19:29:42 +0000 |
commit | e3d3154c1ad7cfd2543bb839623646b942714908 (patch) | |
tree | 99e4afa4f3163d79feb5203ec314776dba6e7a8a | |
parent | d50f287b81011f6a6cb9091a0a9c75f6bbc19966 (diff) | |
parent | 1f502540b71e3c8bca1e01cf5f0417051a9a1275 (diff) | |
download | development-e3d3154c1ad7cfd2543bb839623646b942714908.tar.gz |
Merge "Fix issue #29058724: Improve JobScheduler API demo" into nyc-dev
3 files changed, 37 insertions, 10 deletions
diff --git a/samples/ApiDemos/src/com/example/android/apis/content/JobIds.java b/samples/ApiDemos/src/com/example/android/apis/content/JobIds.java new file mode 100644 index 000000000..14547425c --- /dev/null +++ b/samples/ApiDemos/src/com/example/android/apis/content/JobIds.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2016, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.apis.content; + +/** + * Global constant job IDs used by the app. + */ +public final class JobIds { + static final int MEDIA_CONTENT_JOB = 1; + static final int PHOTOS_CONTENT_JOB = 2; +} diff --git a/samples/ApiDemos/src/com/example/android/apis/content/MediaContentJob.java b/samples/ApiDemos/src/com/example/android/apis/content/MediaContentJob.java index 16c81a38e..3b6e9e416 100644 --- a/samples/ApiDemos/src/com/example/android/apis/content/MediaContentJob.java +++ b/samples/ApiDemos/src/com/example/android/apis/content/MediaContentJob.java @@ -33,7 +33,7 @@ import com.example.android.apis.R; import java.util.List; /** - * Stub job to execute when there is a change to any media: content URI. + * Example stub job to monitor when there is a change to any media: content URI. */ public class MediaContentJob extends JobService { static final Uri MEDIA_URI = Uri.parse("content://" + MediaStore.AUTHORITY + "/"); @@ -50,7 +50,7 @@ public class MediaContentJob extends JobService { public static void scheduleJob(Context context) { JobScheduler js = context.getSystemService(JobScheduler.class); - JobInfo.Builder builder = new JobInfo.Builder(R.id.schedule_media_job, + JobInfo.Builder builder = new JobInfo.Builder(JobIds.MEDIA_CONTENT_JOB, new ComponentName(context, MediaContentJob.class)); builder.addTriggerContentUri(new JobInfo.TriggerContentUri(MEDIA_URI, JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS)); @@ -65,7 +65,7 @@ public class MediaContentJob extends JobService { return false; } for (int i=0; i<jobs.size(); i++) { - if (jobs.get(i).getId() == R.id.schedule_media_job) { + if (jobs.get(i).getId() == JobIds.MEDIA_CONTENT_JOB) { return true; } } @@ -74,7 +74,7 @@ public class MediaContentJob extends JobService { public static void cancelJob(Context context) { JobScheduler js = context.getSystemService(JobScheduler.class); - js.cancel(R.id.schedule_media_job); + js.cancel(JobIds.MEDIA_CONTENT_JOB); } @Override diff --git a/samples/ApiDemos/src/com/example/android/apis/content/PhotosContentJob.java b/samples/ApiDemos/src/com/example/android/apis/content/PhotosContentJob.java index 65ca55e1c..fe87ba4c8 100644 --- a/samples/ApiDemos/src/com/example/android/apis/content/PhotosContentJob.java +++ b/samples/ApiDemos/src/com/example/android/apis/content/PhotosContentJob.java @@ -16,6 +16,9 @@ package com.example.android.apis.content; +import com.example.android.apis.R; + +//BEGIN_INCLUDE(job) import android.app.job.JobInfo; import android.app.job.JobParameters; import android.app.job.JobScheduler; @@ -30,13 +33,11 @@ import android.provider.MediaStore; import android.util.Log; import android.widget.Toast; -import com.example.android.apis.R; - import java.util.ArrayList; import java.util.List; /** - * Stub job to execute when there is a change to photos in the media provider. + * Example stub job to monitor when there is a change to photos in the media provider. */ public class PhotosContentJob extends JobService { // The root URI of the media provider, to monitor for generic changes to its content. @@ -61,7 +62,7 @@ public class PhotosContentJob extends JobService { static final JobInfo JOB_INFO; static { - JobInfo.Builder builder = new JobInfo.Builder(R.id.schedule_photos_job, + JobInfo.Builder builder = new JobInfo.Builder(JobIds.PHOTOS_CONTENT_JOB, new ComponentName("com.example.android.apis", PhotosContentJob.class.getName())); // Look for specific changes to images in the provider. builder.addTriggerContentUri(new JobInfo.TriggerContentUri( @@ -98,7 +99,7 @@ public class PhotosContentJob extends JobService { return false; } for (int i=0; i<jobs.size(); i++) { - if (jobs.get(i).getId() == R.id.schedule_photos_job) { + if (jobs.get(i).getId() == JobIds.PHOTOS_CONTENT_JOB) { return true; } } @@ -108,7 +109,7 @@ public class PhotosContentJob extends JobService { // Cancel this job, if currently scheduled. public static void cancelJob(Context context) { JobScheduler js = context.getSystemService(JobScheduler.class); - js.cancel(R.id.schedule_photos_job); + js.cancel(JobIds.PHOTOS_CONTENT_JOB); } @Override @@ -209,3 +210,4 @@ public class PhotosContentJob extends JobService { return false; } } +//END_INCLUDE(job) |