[英]How to disable HOME key for Android launcher application
是否可以隱藏/禁用屏幕鎖定應用程序的設備主鍵。 我厭倦了創建示例屏幕鎖定應用程序,做了以下測試過程,
在我的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.