I want to make a walkie talkie app that can run even while the screen is off using flutter. Currently i can play the audio even on lockscreen by keeping the app alive. But i want to assign volume up button to be a PTT button. So user can hold the volume up button to start the conversation. Can i do that on flutter?
currently i'm accessing volume button like this
class MainActivity: FlutterActivity() {
private lateinit var channel : MethodChannel;
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "mychannel")
}
// using platform-specific events
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_VOLUME_DOWN -> channel.invokeMethod("volumeBtnPressed", "volume_down")
KeyEvent.KEYCODE_VOLUME_UP -> channel.invokeMethod("volumeBtnPressed", "volume_up")
}
// return true means "prevent default behavior", so volume doesn't change and volume bar doesn't appear
return true
}
}
but it only works on foreground, and sometimes it gives me an Unresolved reference: KeyEvent