I am creating an application and want to do some action when volume button is pressed four times. I am doing like this and its working fine.
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
count++;
if(count==4){
dosomething();
return true;
}
else
return false;
}
}
The problem is that my app is running in the background and as Services are not intended to react on user input so what can be a work around here how can I call my function let say dosomething()
on user input when app is in background. It is the most important part of the application because otherwise purpose of application is destroyed. It cant not necessarily be a volume button, if home or any other works then its fine too. Will really appreciate if anyone can help me.