我最近下载了ACDisplay锁屏应用:
https://play.google.com/store/apps/details?id=com.achep.acdisplay
这个应用程序在我的设备上显示了一个覆盖层,同时也检测到了activity
上的home button click
,这样我就无法绕过锁屏。它还能以某种方式完全隐藏非根设备上的recent button
。那件事怎么可能?
我已经浏览了以下链接:
Detect home button press in android
How can I detect user pressing HOME key in my activity?
How can I detect user pressing HOME key in my activity?
而所有用于旧版本Android
的解决方案都无法检测到home
按钮的点击,因为它可能会被恶意应用程序使用。
这个应用程序是如何做到这一点的?
是否有人可以分享示例代码/应用程序,了解如何防止用户在成功验证自己之前退出锁屏应用程序?
谢谢。
发布于 2019-05-16 23:29:46
WindowManager windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
}
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
layoutParams.x = 0;
layoutParams.y = 0;
layoutParams.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
View window = LayoutInflater.from(this).inflate(R.layout.activity_main, null, false);
windowManager.addView(window, layoutParams);
下面这段代码根据需要阻塞了home、back和recents按钮。
还需要清单中的以下权限:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
https://stackoverflow.com/questions/55224371
复制相似问题