Android Home Screen launch notification
Is that possible to get 开发者_StackOverflow中文版notification when Home button is pressed or Home Screen is launched?
In Android Overriding home key thread i read that "it will be notified when the home screen is about to be launched". So is that possible, if yes how?
Thank you
Is that possible to get notification when Home button is pressed or Home Screen is launched?
Only by being a home screen.
You can simply add this on your activity:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
// Do something
}
return super.onKeyDown(keyCode, event);
}
You can Detect Home Screen is running or not
.
You can see this page for more details,Or you can see this answer.It propose use isScreenOn ()
from PowerManager
(Returns whether the screen is currently on. The screen could be bright or dim):
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
精彩评论