Skip to content

Commit

Permalink
fix: snapshotAction
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Dec 6, 2024
1 parent b82355c commit 72c7999
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@
<service
android:name=".debug.SnapshotActionService"
android:exported="true"
tools:ignore="ExportedService" />
android:foregroundServiceType="specialUse"
tools:ignore="ExportedService">
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="Provide an interface for third-party applications to actively invoke snapshot capturing." />
</service>

<!-- remove useless -->
<activity
Expand Down
15 changes: 8 additions & 7 deletions app/src/main/kotlin/li/songe/gkd/debug/SnapshotActionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package li.songe.gkd.debug
import android.app.Service
import android.content.Intent
import android.os.Binder
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import li.songe.gkd.appScope
import li.songe.gkd.notif.notifyService
import li.songe.gkd.notif.snapshotActionNotif
import li.songe.gkd.util.launchTry

/**
Expand All @@ -15,12 +15,13 @@ class SnapshotActionService : Service() {
override fun onBind(intent: Intent?): Binder? = null
override fun onCreate() {
super.onCreate()
appScope.launch {
delay(1000)
stopSelf()
}
snapshotActionNotif.notifyService(this)
appScope.launchTry {
SnapshotExt.captureSnapshot()
try {
SnapshotExt.captureSnapshot()
} finally {
stopSelf()
}
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/notif/Notif.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,14 @@ val snapshotNotif by lazy {
autoCancel = true,
uri = "gkd://page/2",
)
}

val snapshotActionNotif by lazy {
Notif(
channel = snapshotActionChannel,
id = 105,
text = "快照服务正在运行",
ongoing = true,
autoCancel = false,
)
}
20 changes: 15 additions & 5 deletions app/src/main/kotlin/li/songe/gkd/notif/NotifChannel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,21 @@ val snapshotChannel by lazy {
id = "snapshot", name = "快照通知", desc = "捕获快照后发出通知"
)
}
val snapshotActionChannel by lazy {
NotifChannel(
id = "snapshotAction", name = "快照服务", desc = "供其他程序调用的快照服务"
)
}

fun initChannel() {
createChannel(app, defaultChannel)
createChannel(app, floatingChannel)
createChannel(app, screenshotChannel)
createChannel(app, httpChannel)
createChannel(app, snapshotChannel)
arrayOf(
defaultChannel,
floatingChannel,
screenshotChannel,
httpChannel,
snapshotChannel,
snapshotActionChannel,
).forEach {
createChannel(app, it)
}
}

0 comments on commit 72c7999

Please sign in to comment.