Android Firebase JobService用于侦听目录更改

时间:2018-11-24 14:19:14

标签: android kotlin android-jobscheduler firebase-job-dispatcher android-job

是否有一种方法可以在将文件添加到特定目录后启动JobService?

我尝试使用MediaStore.Files.getContentUri('external'),但没有用。

这是我在MainActivity中安排作业的代码:

val dispatcher = FirebaseJobDispatcher(GooglePlayDriver(context))

            val mediaFileAddedJob = dispatcher.newJobBuilder()
                    .setService(MediaFileReceivedJob::class.java)
                    .setTag("my-media-file-listener")
                    .setRecurring(true)
                    .setLifetime(Lifetime.FOREVER)
                    .setTrigger(Trigger.contentUriTrigger(listOf(
                            ObservedUri(MediaStore.Files.getContentUri("external"), ObservedUri.Flags.FLAG_NOTIFY_FOR_DESCENDANTS),
                            ObservedUri(MediaStore.Files.getContentUri("internal"), ObservedUri.Flags.FLAG_NOTIFY_FOR_DESCENDANTS)
                    )))
                    .setReplaceCurrent(true)
                    .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
                    .build()

            dispatcher.mustSchedule(mediaFileAddedJob)

我要观察的文件是opus音频文件,但是由于某些原因,当将这些特定文件添加到目录中时,MediaStore.Audio.Media.EXTERNAL_CONTENT_URIMediaStore.Audio.Media.INTERNAL_CONTENT_URI不起作用

0 个答案:

没有答案