I was doing some experiments with using JobService and JobScheduler, I followed the the example by android project creating a test service:
https://developer.android.com/codelabs/android-training-job-scheduler
I made a class called ActivityService
which extends the JobService
:
package com.kumaraswamy.jobs;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.util.Log;
public class ActivityService extends JobService {
@Override
public boolean onStartJob(JobParameters jobParameters) {
Log.d("ActivityService", "Received to start");
createNotification();
return false;
}
private void createNotification() {
.........
}
@Override
public boolean onStopJob(JobParameters jobParameters) {
return false;
}
}
And I am starting the service like this:
mScheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE);
ComponentName serviceName = new ComponentName(context.getPackageName(),
ActivityService.class.getName());
JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, serviceName)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
JobInfo myJobInfo = builder.build();
mScheduler.schedule(myJobInfo);
Toast.makeText(context, "Job Scheduled, job will run when " +
"the constraints are met.", Toast.LENGTH_SHORT).show();
if (mScheduler!= null){
mScheduler.cancelAll();
mScheduler = null;
Toast.makeText(context, "Jobs cancelled", Toast.LENGTH_SHORT).show();
}
And annotations declared:
@UsesServices(services = @ServiceElement(name = "com.kumaraswamy.jobs.ActivityService", exported = "true"))
@UsesPermissions(permissionNames = "android.permission.BIND_JOB_SERVICE")
First I had got error the service not found and somehow I managed to fix it but now I face the error:
Runtime Error
Sheduled service (com.kumaraswamy....) does not require android.permission.BIND_JOB_SERVICE
I removed the permission as the error said, the same thing happened. I have also enabled the exported to true. I also tried the class making it class static but that produced the same error. I checked the compiled manifest file and everything well was present. Please tell me if I am doing something wrong.