获取前台服务Android的根视图
我有一个应用程序,它有一个前台服务,可以从麦克风录制然后处理,现在我想创建另一个后台运行的前台服务来捕获android屏幕,然后也处理捕获的图像,但我不知道怎么做。这是我发现做屏幕捕获工作,但它关闭了,只要我按下应用程序图标,我无法启动录音服务,我在这里找到的,这是应用程序。如果我使用此代码:获取前台服务Android的根视图,android,kotlin,screen-capture,Android,Kotlin,Screen Capture,我有一个应用程序,它有一个前台服务,可以从麦克风录制然后处理,现在我想创建另一个后台运行的前台服务来捕获android屏幕,然后也处理捕获的图像,但我不知道怎么做。这是我发现做屏幕捕获工作,但它关闭了,只要我按下应用程序图标,我无法启动录音服务,我在这里找到的,这是应用程序。如果我使用此代码: private fun takeScreenshot() { val now = Date() DateFormat.format("yyyy-MM-dd_hh:mm:ss&q
private fun takeScreenshot() {
val now = Date()
DateFormat.format("yyyy-MM-dd_hh:mm:ss", now)
val now2= now.toString().split(" ")
try {
// image naming and path to include sd card appending name you choose for file
val mPath: String =
getExternalFilesDir(null).toString().toString() + "/" + now2 + ".png"
Log.d("path",mPath)
// create bitmap screen capture
val v1 = window.decorView.rootView
v1.isDrawingCacheEnabled = true
val bitmap = Bitmap.createBitmap(v1.drawingCache)
v1.isDrawingCacheEnabled = false
val imageFile = File(mPath)
val outputStream = FileOutputStream(imageFile)
val quality = 100
bitmap.compress(Bitmap.CompressFormat.PNG, quality, outputStream)
outputStream.flush()
outputStream.close()
} catch (e: Throwable) {
// Several error may come out with file handling or DOM
e.printStackTrace()
}
}
我无法从前台服务获取rootview。请帮帮我