Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
PDF Viewer Scanner White
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
PDF Viewer Scanner White
Commits
a748883a
Commit
a748883a
authored
Nov 09, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
6072b4d3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
21 deletions
+30
-21
StayJobService.kt
.../com/base/pdfviewerscannerwhite/service/StayJobService.kt
+30
-21
No files found.
app/src/main/java/com/base/pdfviewerscannerwhite/service/StayJobService.kt
View file @
a748883a
...
...
@@ -32,15 +32,14 @@ import com.base.pdfviewerscannerwhite.utils.LogEx
class
StayJobService
:
JobService
()
{
init
{
val
builder
=
Configuration
.
Builder
()
builder
.
setJobSchedulerJobIdRange
(
0
,
1000
)
}
private
val
TAG
=
"Stay
Notification
Service"
val
channelName
=
"PDF Reader Foreground Service Channel"
val
channelId
=
"PDF_Reader_Service_Id"
val
NOTIFICATION_PERMANENT_ID
=
186
private
val
TAG
=
"Stay
Job
Service"
private
val
channelName
=
"PDF Reader Foreground Service Channel"
private
val
channelId
=
"PDF_Reader_Service_Id"
private
val
NOTIFICATION_PERMANENT_ID
=
186
companion
object
{
...
...
@@ -111,6 +110,7 @@ class StayJobService : JobService() {
override
fun
onStartCommand
(
intent
:
Intent
?,
flags
:
Int
,
startId
:
Int
):
Int
{
//监听媒体库变化
observerMediaContentObserver
()
...
...
@@ -132,6 +132,15 @@ class StayJobService : JobService() {
isRunning
=
true
}
private
fun
notifyForeground
()
{
val
notificationManager
=
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
notificationManager
.
notify
(
NOTIFICATION_PERMANENT_ID
,
createPermanentNotification
(
applicationContext
)
)
}
override
fun
onDestroy
()
{
isRunning
=
false
...
...
@@ -139,12 +148,11 @@ class StayJobService : JobService() {
}
override
fun
onCreate
()
{
LogEx
.
logDebug
(
TAG
,
"onCreate isRunning=$isRunning"
)
if
(!
isRunning
)
{
startForeground
()
isRunning
=
true
Timer
{
startForeground
()
}.
apply
{
start
()
}
startForeground
()
Timer
().
start
()
}
super
.
onCreate
()
}
...
...
@@ -157,6 +165,18 @@ class StayJobService : JobService() {
return
false
}
private
inner
class
Timer
()
:
CountDownTimer
(
30000
,
1000
)
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
}
override
fun
onFinish
()
{
notifyForeground
()
Timer
().
start
()
}
}
private
var
mediaContentObserver
:
MediaContentObserver
?
=
null
private
fun
observerMediaContentObserver
()
{
...
...
@@ -168,19 +188,8 @@ class StayJobService : JobService() {
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
,
true
,
it
)
}
}
}
}
class
Timer
(
val
block
:
()
->
Unit
)
:
CountDownTimer
(
30000
,
1000
)
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
}
override
fun
onFinish
()
{
Timer
{
block
()
}.
apply
{
start
()
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment