如何在屏幕镜像期间锁定android屏幕?
我正在开发一个android应用程序,用于将android屏幕镜像到汽车显示器上。我使用MediaProjection获取屏幕;使用那个api,我可以镜像屏幕,现在我想在镜像过程中锁定android屏幕,以避免用户分心如何在屏幕镜像期间锁定android屏幕?,android,lockscreen,mirroring,android-screen,android-mediaprojection,Android,Lockscreen,Mirroring,Android Screen,Android Mediaprojection,我正在开发一个android应用程序,用于将android屏幕镜像到汽车显示器上。我使用MediaProjection获取屏幕;使用那个api,我可以镜像屏幕,现在我想在镜像过程中锁定android屏幕,以避免用户分心 在流媒体播放期间,是否有任何方法仅锁定Android设备屏幕?例如,显示固定图片或冻结设备屏幕并流式显示其他布局?可能使用一些API或其他?我个人通过设置/清除标志为用户锁定/解锁UI: //The user cannot interact with the UI private
在流媒体播放期间,是否有任何方法仅锁定Android设备屏幕?例如,显示固定图片或冻结设备屏幕并流式显示其他布局?可能使用一些API或其他?我个人通过设置/清除标志为用户锁定/解锁UI:
//The user cannot interact with the UI
private void disableUserInteraction() {
(getActivity()).getWindow()
.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
//The user can interact with the UI
private void enableUserInteraction() {
(getActivity()).getWindow()
.clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
这将阻止用户与屏幕交互。
然后,您可以创建一个浅灰色的RelativeLayout,以明确用户需要等待,并在执行操作时利用其可见性:
<LinearLayout
android:id="@+id/loading_mask"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#B0000000"
android:visibility="gone"/>
如果您将这三种方法结合起来,我认为这是一个很好的等待屏幕,然后您可以将这些方法组合在一起,如下所示:
//The user can interact with the UI, end of progressdialog and waiting mask
private void unlockUI() {
loadingMask.setVisibility(View.GONE);
dismissProgressDialog();
enableUserInteraction();
}
//The user cannot interact with the UI, start of progressdialog and waiting mask
private void lockUI() {
showProgressDialog();
disableUserInteraction();
loadingMask.setVisibility(View.VISIBLE);
}
当您启动时只需调用lockUI(),当用户可以再次与屏幕交互时,您只需调用unlockUI()
希望这有帮助,让我们知道它是如何进行的 欢迎来到SO!在一个问题中应该有一个最小的内容:输入样本(如果需要)、预期输出样本(需要)、您尝试了什么、您研究了什么。。。你试了什么?谢谢你的回答。但是如果我这样做,屏幕的两边都会被锁定。汽车显示器和手机。我只想锁定Android屏幕,只在汽车显示屏上显示屏幕。
//The user can interact with the UI, end of progressdialog and waiting mask
private void unlockUI() {
loadingMask.setVisibility(View.GONE);
dismissProgressDialog();
enableUserInteraction();
}
//The user cannot interact with the UI, start of progressdialog and waiting mask
private void lockUI() {
showProgressDialog();
disableUserInteraction();
loadingMask.setVisibility(View.VISIBLE);
}