1

I am developing an android application for mirroring android screen to car display. I used MediaProjection for getting screen; using that api I was able to mirror screen and now I want to lock android screen during mirroring to avoid distraction of user.

Is there any way to lock only Android device screen during streaming? for example showing a fixed picture or freeze Device screen and stream the other layouts? Maybe using some APIs or etc?

ET1992
  • 151
  • 9
  • Welcome to SO! There should be a minimum content in one question: Input sample (if needed), expected output sample (is needed), what you try, what you research... What did you try? – David García Bodego Nov 14 '19 at 09:20

1 Answers1

0

I personally lock/unlock the UI for users by setting / clearing flags :

//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);
}

This will prevent the user to interact with the screen. You can then create a RelativeLayout with grayish color to make it obvious that the user needs to wait, and playing with its visibility when performing your actions :

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

You can also add a ProgressDialog at the same time, that you show / dismiss :

//The UI message to show the user during the loading 
private void showProgressDialog() {
    if (progressDialog == null) {
        progressDialog = new ProgressDialog(Objects.requireNonNull(getParentFragment())
                .getActivity());
        progressDialog.setIndeterminate(true);
        progressDialog.setCancelable(false);
    }
    progressDialog.setMessage("Loading...");
    progressDialog.show();
}

private void dismissProgressDialog() {
    if (progressDialog != null) {
        progressDialog.dismiss();
    }
}

If you combine those three, I think it make a good waiting screen, then you can put those methods together like so :

//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);
}

And you just need to call lockUI() when you start and unlockUI() when the user can interact again with the screen.

Hope this helps, let us know how it went !

  • Thanks for your answer. But if I do this, the screen will be locked in both sides. car display and the mobile. I want to Lock only Android Screen and Show screen only on car display. – ET1992 Nov 16 '19 at 08:22