I am trying to override the onkeylongpress method in my activity to detect long press of the power button, but nothing happens. It looks like the system is dropping the code in the method.
I have implemented a solution from this site where you track the long press with the method onkeypress, but the toast code does not show up. I have also declared the permission <uses-permission android:name="android.permission.PREVENT_POWER_KEY" />.
The code is not working so I assumed Google did something to the permission. The Android Java code I am using to achieve this with is below:
public override bool OnKeyDown(Keycode keyCode, KeyEvent e)
{
if (keyCode == Keycode.Power)
{
// Start tracking
e.StartTracking();
return true;
}
return base.OnKeyDown(keyCode, e);
}
public override bool OnKeyLongPress(Keycode keyCode, KeyEvent e)
{
if (keyCode == Keycode.Power)
{
// Show a toast
Toast.MakeText(this, "Power button long press", ToastLength.Long).Show();
return true;
}
else
{
return OnKeyLongPress(keyCode, e);
}
}