[英]How to disable HOME key for Android launcher application
Is it possible to hide/disable Device home key for Screen lock application. 是否可以隐藏/禁用屏幕锁定应用程序的设备主键。 I tired to create a sample screen lock application, i did the following testing process,
我厌倦了创建示例屏幕锁定应用程序,做了以下测试过程,
In my manifest.xml is, 在我的manifest.xml中,
<activity
android:name=".SampleLock"
android:excludeFromRecents="true"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:persistent="true"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<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.MONKEY" /> -->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Guys any idea to resolve this issue? 你们有解决这个问题的想法吗?
For disabling home button just add this permission in your Manifest.xml: 要禁用主页按钮,只需在您的Manifest.xml中添加此权限:
< uses-permission android:name="android.permission.GET_TASKS"/> <users-permission android:name =“ android.permission.GET_TASKS” />
For disabling Recent button add this code to your Main activity: 要禁用“最近使用”按钮,请将此代码添加到您的“主要”活动中:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (!hasFocus) {
windowCloseHandler.post(windowCloserRunnable);
}
}
private void toggleRecents() {
Intent closeRecents = new Intent("com.android.systemui.recent.action.TOGGLE_RECENTS");
closeRecents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
ComponentName recents = new ComponentName("com.android.systemui", "com.android.systemui.recent.RecentsActivity");
closeRecents.setComponent(recents);
this.startActivity(closeRecents);
}
private Handler windowCloseHandler = new Handler();
private Runnable windowCloserRunnable = new Runnable() {@Override public void run() {
ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
if (cn != null && cn.getClassName().equals("com.android.systemui.recent.RecentsActivity")) {
toggleRecents();
}
}
};
remove this line from your manifest deceleration 从清单减速中删除此行
<category android:name="android.intent.category.LAUNCHER" />
it must be 一定是
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.