title: Schedule Job for file change notifications
body: <p>I want to be notified when a specific file changes. I was looking into <code>FileObserver</code> but after having read the answer in <a href="https://stackoverflow.com/a/44543756/805673">this thread</a>, I've tried to accomplish my target with a <code>JobScheduler</code> that should run the job when the file changes, using <a href="https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#addTriggerContentUri(android.app.job.JobInfo.TriggerContentUri)" rel="nofollow noreferrer"><code>addTriggerContentUri()</code></a>.</p>
  
  <p>I started by copying the example from the documentation page, changing the <code>Uri</code> that should trigger the job to <code>Uri.fromFile(File(&lt;path-to-file&gt;))</code>. Unfortunately, my <code>onStartJob()</code> method is never called although <code>JobScheduler::schedule()</code> returns success.</p>
  
  <p>Now, I am wondering if I've done anything wrong or if there is a general flaw in my interpretations, maybe it is just impossible to trigger a job on ordinary file changes?</p>
  
  <p>The stripped-down version of my class/code looks like this (Kotlin):</p>
  
  <pre><code>class FilechangeService : JobService() {
  
      companion object {
  
          private const val JOB_ID = 0
  
          // Schedule this job, replace any existing one.
          fun scheduleJob(context: Context) {
  
              // JobInfo Builder to construct the Job
              val builder = JobInfo.Builder(
                  JOB_ID,
                  ComponentName(context, FilechangeService::class.java)
              )
              // Look for changes to specific file
              val uri = Uri.fromFile(File(&lt;path-to-file&gt;))
              builder.addTriggerContentUri(
                  JobInfo.TriggerContentUri(uri, 0)
              )
              val jobInfo = builder.build()
              val js = context.getSystemService(JobScheduler::class.java)
              val status = js.schedule(jobInfo)
          }
      }
  
      override fun onStartJob(params : JobParameters) : Boolean {
          // Code that is never executed =(
          return false
      }
  }
  </code></pre>
  
  <p>Of course, <code>FilechangeService::scheduleJob()</code> is called from an other part of my application. Furthermore, I have added the Service to my AndroidManifest.xml with <code>android:permission="android.permission.BIND_JOB_SERVICE"</code>.</p>
  
  <p>Thanks in advance for any help!</p>