简体   繁体   English

如何为Android启动器应用程序禁用HOME键

[英]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, 我厌倦了创建示例屏幕锁定应用程序,做了以下测试过程,

  1. Device screen is off 设备屏幕关闭
  2. Clicked search button - Lock screen will appear and nothing will happened 单击搜索按钮-将会出现锁定屏幕,什么也不会发生
  3. Clicked Back button - Lock screen will appear and nothing will happened 单击“后退”按钮-将会出现锁定屏幕,什么也不会发生
  4. Clicked Menu button - Lock screen will appear and nothing will happened 单击菜单按钮-将会出现锁定屏幕,什么也不会发生
  5. Clicked Home Button - Lock screen will removed and redirect to device home page. 单击主页按钮-锁定屏幕将被删除并重定向到设备主页。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM