I have a method that stop the my app ringing tone.
CommonUtils.pauseAlarm();
and i want to apply these methods on Device home button click but it does not get home button click event.
All key event detect like menu,up, down button click but not get home button click
if ((keyCode == KeyEvent.KEYCODE_HOME)) {
CommonUtils.pauseAlarm();// background services
return true;
}
I have search many sites, some sites give the solution like
@Override
protected void onUserLeaveHint() {
Log.d("onUserLeaveHint", "Home button pressed");
CommonUtils.pauseMusic();
super.onUserLeaveHint();
}
Also i am try this function
@Override
public void onPause(){
super.onPause();
CommonUtils.pauseMusic();
}
but those method also call on my app another button click event So please give me any idea? What i am doing wrong.
Android has stopped users from modifying the action that the Home Button has.
As stated by silvia-aut (answer)
On older Android version this is working. But Android changed this, because they say "Home Button should stay Home Button" and they don't want that anybody override the Home Button. And because of this reason your code is not working anymore.
If you want to do something when the home button is pressed, then do this in the onPause method.
Secondly, try to first call your method, then pause:
@Override
public void onPause(){
CommonUtils.pauseMusic();
super.onPause();
}