【发布时间】:2013-12-30 13:56:47
【问题描述】:
我正在创建一个示例锁屏应用程序,我必须覆盖主页按钮,在我研究了谷歌和 stackoverflow 之后,我得到了结果,做起来很复杂。这里我提到了我在我的应用程序中所做的事情,
使用广播接收器创建了一个服务,以在屏幕关闭时显示我的锁定屏幕。 - 工作正常。
-
为了覆盖主页、菜单、返回和搜索按钮,我使用了以下代码, 希望当应用程序仅成为启动器时我们可以覆盖主页按钮,因此在我的 manifest.xml 中添加了此代码。
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> <!-- <category android:name="android.intent.category.LAUNCHER" /> --> </intent-filter>
在我的活动中我也使用了这个代码
@Override
public void onAttachedToWindow() {
// TODO Auto-generated method stub
this.getWindow().setType(
WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
| WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
到目前为止,在我的示例应用程序中,我成功完成了上述操作。现在我的问题是,
当我解锁屏幕然后转到任何应用程序,然后单击设备主页按钮,我的锁定屏幕将出现。我厌倦了禁用此功能,但我不知道该怎么做,为此我使用了如下代码,
/* This should come from a preference that let's the user select an activity that can handle the HOME intent */
String packageName = "com.android.launcher";
String packageClass = "com.android.launcher2.Launcher";
Intent home_intent = new Intent(Intent.ACTION_MAIN);
home_intent.addCategory(Intent.CATEGORY_HOME);
home_intent.setComponent(new ComponentName(packageName, packageClass));
home_intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
/* Here you should catch the exception when the launcher has been uninstalled, and let the user save themselves by opening the Market or an app list or something. Users sometimes use root apps to uninstall the system launcher, so your fake launcher is all that is left. Might as well give the poor user a hand. */
startActivity(home_intent);
没有代码可以帮助我,我的确切需求是一旦我解锁屏幕,我需要显示默认主屏幕,直到屏幕关闭屏幕。有什么想法来处理这个问题吗?提前致谢。
【问题讨论】:
标签: android android-homebutton