开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜