Java 安卓启动器-主页按钮
我正在为Android开发一个主屏幕启动程序。Java 安卓启动器-主页按钮,java,android,android-launcher,Java,Android,Android Launcher,我正在为Android开发一个主屏幕启动程序。 现在,如果用户已经在主屏幕上, 当用户按下Home按钮时,我需要一个自定义操作 我知道其他一些启动器,可以覆盖homebutton, 例如Go Launcher Ex 我的代码是: @Override public boolean dispatchKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode();
现在,如果用户已经在主屏幕上,
当用户按下Home按钮时,我需要一个自定义操作 我知道其他一些启动器,可以覆盖homebutton,
例如Go Launcher Ex 我的代码是:
@Override
public boolean dispatchKeyEvent(KeyEvent event)
{
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (action)
{
case KeyEvent.ACTION_DOWN:
switch (keyCode)
{
case KeyEvent.KEYCODE_HOME:
break;
}
break;
case KeyEvent.ACTION_UP:
switch (keyCode)
{
case KeyEvent.KEYCODE_HOME:
if (!event.isCanceled())
Log.i("TEST", "HOME");
break;
}
break;
}
return super.dispatchKeyEvent(event);
}
但当我按下Home(主页)按钮时,什么也没有发生。引用以下内容:
对不起,您无法“检测主按键按下事件”
然而,在同一篇文章中,Idistic建议将此作为一种解决方法:
long userInteractionTime = 0;
@Override
public void onUserInteraction() {
userInteractionTime = System.currentTimeMillis();
super.onUserInteraction();
Log.i("appname","Interaction");
}
@Override
public void onUserLeaveHint() {
long uiDelta = (System.currentTimeMillis() - userInteractionTime);
super.onUserLeaveHint();
Log.i("bThere","Last User Interaction = "+uiLag);
if (uiDelta < 100)
Log.i("appname","Home Key Pressed");
else
Log.i("appname","We are leaving, but will probably be back shortly!");
}
long userInteractionTime=0;
@凌驾
公共关系{
userInteractionTime=System.currentTimeMillis();
super.onUserInteraction();
Log.i(“appname”、“Interaction”);
}
@凌驾
public void onUserLeaveHint(){
长uiDelta=(System.currentTimeMillis()-userInteractionTime);
super.onUserLeaveHint();
Log.i(“bThere”,“Last User Interaction=“+uiLag”);
if(uiDelta<100)
Log.i(“appname”,“按下主键”);
其他的
i(“appname”,“我们要离开了,但可能很快就会回来!”);
}
引用此:
对不起,您无法“检测主按键按下事件”
然而,在同一篇文章中,Idistic建议将此作为一种解决方法:
long userInteractionTime = 0;
@Override
public void onUserInteraction() {
userInteractionTime = System.currentTimeMillis();
super.onUserInteraction();
Log.i("appname","Interaction");
}
@Override
public void onUserLeaveHint() {
long uiDelta = (System.currentTimeMillis() - userInteractionTime);
super.onUserLeaveHint();
Log.i("bThere","Last User Interaction = "+uiLag);
if (uiDelta < 100)
Log.i("appname","Home Key Pressed");
else
Log.i("appname","We are leaving, but will probably be back shortly!");
}
long userInteractionTime=0;
@凌驾
公共关系{
userInteractionTime=System.currentTimeMillis();
super.onUserInteraction();
Log.i(“appname”、“Interaction”);
}
@凌驾
public void onUserLeaveHint(){
长uiDelta=(System.currentTimeMillis()-userInteractionTime);
super.onUserLeaveHint();
Log.i(“bThere”,“Last User Interaction=“+uiLag”);
if(uiDelta<100)
Log.i(“appname”,“按下主键”);
其他的
i(“appname”,“我们要离开了,但可能很快就会回来!”);
}
启动器是一种活动
所以我相信当用户按下home按钮时,您将获得焦点。有一件事我可以肯定地告诉你。这是可能的
在视图类中设置了setOnFocusChanged(),Launcher是一种活动 所以我相信当用户按下home按钮时,您将获得焦点。有一件事我可以肯定地告诉你。这是可能的 您在视图类中获得了setOnFocusChanged()