mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 11:42:22 +08:00
perf: hide screenshot on android<11
This commit is contained in:
parent
5d467b890e
commit
08074bb833
|
@ -5,8 +5,10 @@
|
|||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||
|
||||
<!-- 低版本Android截屏 -->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
|
||||
<!-- 低版本Android截屏, Android 11 上可以使用无障碍 takeScreenshot 截屏 -->
|
||||
<uses-permission
|
||||
android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION"
|
||||
android:maxSdkVersion="29" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Activity
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.projection.MediaProjectionManager
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
|
@ -256,27 +257,30 @@ fun AdvancedPage() {
|
|||
}
|
||||
)
|
||||
|
||||
val screenshotRunning by ScreenshotService.isRunning.collectAsState()
|
||||
TextSwitch(
|
||||
name = "截屏服务",
|
||||
desc = "生成快照需要获取屏幕截图,Android11无需开启",
|
||||
checked = screenshotRunning,
|
||||
onCheckedChange = scope.launchAsFn<Boolean> {
|
||||
if (it) {
|
||||
if (!checkOrRequestPermission(context, notificationState)) {
|
||||
return@launchAsFn
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||
val screenshotRunning by ScreenshotService.isRunning.collectAsState()
|
||||
TextSwitch(
|
||||
name = "截屏服务",
|
||||
desc = "生成快照需要获取屏幕截图",
|
||||
checked = screenshotRunning,
|
||||
onCheckedChange = scope.launchAsFn<Boolean> {
|
||||
if (it) {
|
||||
if (!checkOrRequestPermission(context, notificationState)) {
|
||||
return@launchAsFn
|
||||
}
|
||||
val mediaProjectionManager =
|
||||
context.getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
|
||||
val activityResult =
|
||||
launcher.launchForResult(mediaProjectionManager.createScreenCaptureIntent())
|
||||
if (activityResult.resultCode == Activity.RESULT_OK && activityResult.data != null) {
|
||||
ScreenshotService.start(intent = activityResult.data!!)
|
||||
}
|
||||
} else {
|
||||
ScreenshotService.stop()
|
||||
}
|
||||
val mediaProjectionManager =
|
||||
context.getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
|
||||
val activityResult =
|
||||
launcher.launchForResult(mediaProjectionManager.createScreenCaptureIntent())
|
||||
if (activityResult.resultCode == Activity.RESULT_OK && activityResult.data != null) {
|
||||
ScreenshotService.start(intent = activityResult.data!!)
|
||||
}
|
||||
} else {
|
||||
ScreenshotService.stop()
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
val floatingRunning by FloatingService.isRunning.collectAsState()
|
||||
TextSwitch(
|
||||
|
@ -301,7 +305,7 @@ fun AdvancedPage() {
|
|||
|
||||
TextSwitch(
|
||||
name = "音量快照",
|
||||
desc = "当音量变化时,生成快照,如果悬浮窗按钮不工作,可以使用这个",
|
||||
desc = "音量变化时生成快照,悬浮窗按钮不工作时使用",
|
||||
checked = store.captureVolumeChange
|
||||
) {
|
||||
storeFlow.value = store.copy(
|
||||
|
|
Loading…
Reference in New Issue
Block a user