Search code examples
androidandroid-alertdialogscreen-capture

Detect key presses on Start Capturing Dialog


Problem Description

I'm using Native Screen Recording functionality provided by Android. When I start recording System popups Dialog and ask user to confirm that screen can be recorder. If user press outside dialog dismissed (same behaviour when he/she press cancel) when press Start Now Recording Start.

Question

  1. How I can detect what user pressed

    • Cancel
    • Start Now
    • Dismissed on press outside
  2. How can I disable dismiss on press outside of dialog

  3. Is there a way to avoid showing dialog?

Screenshot

enter image description here


Solution

  • How I can detect what user pressed

    You can determine if the user pressed "Start Now" as part of your normal media projection flow. For example, when you pass the onActivityResult() data to getMediaProjection(), getMediaProjection() will only give you a MediaProjection object if the user pressed "Start Now".

    You cannot distinguish between "Cancel", "click outside the dialog", pressing the BACK button, pressing Esc on a device with a physical keyboard, or any other means of dismissing this dialog.

    How can I disable dismiss on press outside of dialog

    The decision on how to handle this is up to the system, not you.

    Is there a way to avoid showing dialog?

    No.