簡體   English   中英

如何為Android啟動器應用程序禁用HOME鍵

[英]How to disable HOME key for Android launcher application

是否可以隱藏/禁用屏幕鎖定應用程序的設備主鍵。 我厭倦了創建示例屏幕鎖定應用程序,做了以下測試過程,

  1. 設備屏幕關閉
  2. 單擊搜索按鈕-將會出現鎖定屏幕,什么也不會發生
  3. 單擊“后退”按鈕-將會出現鎖定屏幕,什么也不會發生
  4. 單擊菜單按鈕-將會出現鎖定屏幕,什么也不會發生
  5. 單擊主頁按鈕-鎖定屏幕將被刪除並重定向到設備主頁。

在我的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>

你們有解決這個問題的想法嗎?

要禁用主頁按鈕,只需在您的Manifest.xml中添加此權限:

<users-permission android:name =“ android.permission.GET_TASKS” />

要禁用“最近使用”按鈕,請將此代碼添加到您的“主要”活動中:

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

從清單減速中刪除此行

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM