如何禁用Android launcher应用程序的HOME键

如何禁用Android launcher应用程序的HOME键,android,Android,是否可以隐藏/禁用屏幕锁定应用程序的设备主控键。为了创建一个示例屏幕锁定应用程序,我做了以下测试过程 设备屏幕关闭 点击搜索按钮-锁定屏幕将出现,不会发生任何事情 单击后退按钮-锁定屏幕将出现,不会发生任何事情 点击菜单按钮-锁定屏幕将出现,不会发生任何事情 单击主页按钮-锁定屏幕将被删除并重定向到设备主页。 在我的manifest.xml中 <activity android:name=".SampleLock" android:exclu

是否可以隐藏/禁用屏幕锁定应用程序的设备主控键。为了创建一个示例屏幕锁定应用程序,我做了以下测试过程

  • 设备屏幕关闭
  • 点击搜索按钮-锁定屏幕将出现,不会发生任何事情
  • 单击后退按钮-锁定屏幕将出现,不会发生任何事情
  • 点击菜单按钮-锁定屏幕将出现,不会发生任何事情
  • 单击主页按钮-锁定屏幕将被删除并重定向到设备主页。
  • 在我的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>
    
    
    

    有什么办法解决这个问题吗?

    从清单中删除这一行

    <category android:name="android.intent.category.LAUNCHER" />
    
    
    
    一定是

    <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>
    

    要禁用主页按钮,只需在Manifest.xml中添加此权限:

    要禁用“最近使用”按钮,请将此代码添加到主要活动:

    @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();
        }
    }
    };
    

    @哈迪克:那么GoLocker和其他储物柜应用程序是怎么做的呢?很抱歉评论过快,请看我的答案这是你的答案@Hardik:No probs。。但我也已经这么做了。。这对我没用(你试过这个吗