是否可以隐藏/禁用屏幕锁定应用程序的设备主页键。我厌倦了创建一个示例屏幕锁定应用程序,我做了以下测试过程,
在我的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>
有谁想解决这个问题?
答案 0 :(得分:1)
要禁用主页按钮,只需在Manifest.xml中添加此权限:
&LT; uses-permission android:name =&#34; android.permission.GET_TASKS&#34; /&gt;
要禁用“最近”按钮,请将此代码添加到主要活动:
@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();
}
}
};
答案 1 :(得分:0)
从清单减速中删除此行
<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>