Hello,
I need to intercept the long press of a physical key (any) at any time.
Through the OnKeyUp and OnKeyDown methods it work properly, but it only works as long as the app is active.
If the device is put on standby or if the lock screen is active, it no longer works.
How can this result be achieved?
Thanks
I need to intercept the long press of a physical key (any) at any time.
To intercept key event at any time, try to use BroadcastReceiver to achieve this. A broadcast receiver allows an application to respond to messages (an Android Intent) that are broadcast by the Android operating system or by an application.
[BroadcastReceiver(Enabled = true, Exported = false)] public class SampleReceiver : BroadcastReceiver { public override void OnReceive(Context context, Intent intent) { // Do stuff here. } }
Tutorial about Broadcast Receivers:
https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/broadcast-receivers
https://developer.android.com/guide/topics/media-apps/mediabuttons
Answers
To intercept key event at any time, try to use BroadcastReceiver to achieve this. A broadcast receiver allows an application to respond to messages (an Android Intent) that are broadcast by the Android operating system or by an application.
Tutorial about Broadcast Receivers:
https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/broadcast-receivers
https://developer.android.com/guide/topics/media-apps/mediabuttons
We will try to deepen this information to adapt it to our uses.
Thank you for your suggestion.
Do you have some update? If the reply solved your issue, please mark the helpful reply as answer. If you are facing some issues while implementing, try to post the particular error with the corresponding codes here.
Good evening Jarvan,
I'm sorry but due to contingent problems we haven't yet been able to test the proposed solution for the moment.
It will be my duty to inform you asap, in the meantime if you need to mark the topic as closed I think it is right.
Thanks