title: Android JobScheduler - can't create a persistent job
body: <p>I am trying out the new JoScheduler API that has come with Android Lollipop. I have so far managed to successfully create and have a job run with a delay of 6000 milliseconds with no network requirements without an issue.</p>
  
  <p>However, I have just tried to persist the same job via using the setPersisted(true) function. As soon as the job build() function is called it now fails saying that I need the RECEIVED_BOOT_COMPLETED permission in the Manifest file.</p>
  
  <p>But I have added the permission:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.android" &gt;
  
    &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
  </code></pre>
  
  <p>I have even added the following code before the job is added to see if the app has the permission registered:</p>
  
  <pre><code>PackageManager pm = context.getPackageManager();
  int hasPerm = pm.checkPermission(Permission.RECEIVE_BOOT_COMPLETED, 
  context.getPackageName());
  if (hasPerm == PackageManager.PERMISSION_GRANTED)
  {
     // Goes into here every time
  }
  </code></pre>
  
  <p>However, when the job is built I get the following error:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Error: requested job be persisted without holding RECEIVE_BOOT_COMPLETED permission.
  </code></pre>
  
  <p>My code to create and add the job to the JobSchedular:</p>
  
  <pre><code>ComponentName serviceComponent = new ComponentName(getApplicationContext(), MyJobService.class);
  JobInfo.Builder builder = new JobInfo.Builder(1, serviceComponent)
          .setMinimumLatency(6000)
          .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
          .setPersisted(true);
  JobScheduler jobScheduler = (JobScheduler) getApplicationContext().getSystemService(Context.JOB_SCHEDULER_SERVICE);
  jobScheduler.schedule(builder.build());
  </code></pre>
  
  <p>My JobService manifest declaration:</p>
  
  <pre><code>&lt;service
          android:name=".service.MyJobService"
          android:permission="android.permission.BIND_JOB_SERVICE"
          android:exported="true" &gt;
      &lt;/service&gt;
  </code></pre>
  
  <p>So I am wondering if I am doing something else wrong that anyone can spot. The only thing i'll note incase it does make a difference is that the code is run in an IntentService so I am wondering if this might be a reason why the JobScheduler can't find the permission.</p>