1

I need to answer to the YES/NO system dialog programmatically

for example this code closes any dialog that comes to the screen

public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    Log.e("Focus debug", "Focus changed !");

    if (!hasFocus) {
        Log.e("Focus debug", "Lost focus !");

        Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        sendBroadcast(closeDialog);

    }
}

is it possible to do something else ? to click YES or NO on that dialog ???

I searched for something different from ACTION_CLOSE_SYSTEM_DIALOGS but I got nothing

I might need to catch the dialog first .. then I need to click yes when the phone shows yes/no dialog asking the user to enable the bluetooth is it possible?

2 Answers2

0

In the API docs it says this about the ACTION_CLOSE_SYSTEM_DIALOGS action:

Broadcast Action: This is broadcast when a user action should request a temporary system dialog to dismiss.

You are simply requesting that the dialog be dismissed and therefore it is up to the dialog to accept the request or not. What this means is that some (most?) dialogs will not be dismissed. Android is setup to sandbox applications and any interaction with system components will be limited at best. I haven't been able to find any further information on how you may be able to request that a dialog accept a specific option, but I would suggest that if it's at all possible, then it will only work on very specific system dialogs.

TheIT
  • 11,919
  • 4
  • 64
  • 56
0

You can do it with ADB touch events. First you need the location of touch:

adb shell getevent -l

Then you need to send the event:

adb shell input tap <x> <y>

You can also run adb commands programmatically (just remove the adb shell part):

Runtime.getRuntime().exec("input tap <x> <y>");   

You can see how to get values from the shell programmatically here: https://stackoverflow.com/a/66499406/804894

tricknology
  • 1,092
  • 1
  • 15
  • 27