我在API 21及更高版本上做了频闪仪。频闪仪工作正常,但是当我关闭电源时,出现以下错误:
android.app.IntentReceiverLeaked: Service
co.onlini.piuAlarm.domain.service.AlarmService has leaked IntentReceiver
android.hardware.camera2.CameraManager$1@261b1d that was originally registered
here. Are you missing a call to unregisterReceiver()?
我的频闪实现:
class StrobeRunner(var cameraManager: CameraManager, var on: Boolean, var id: String) : Runnable {
var isOnOff = false
fun stop(){
on = false
run()
}
override fun run() {
while (on) {
cameraManager.setTorchMode(id, true)
Thread.sleep(500.toLong())
cameraManager.setTorchMode(id, false)
Thread.sleep(500.toLong())
}
}
}
我不明白如何在unregisterReceiver()中退订?
或者也许有人知道在哪里观看Api 21+的闪光灯的实现?
我为上一个api尝试了this和this以及其他选项。我不知道为什么,但是,如果您尝试在另一个流中根据此原理打开闪光灯,则不会打开它,但是在mainThread中没有问题。