Control an Android Phone with Gemini 3.5 Flash Computer Use
June 25, 2026 9 minute read View Code
Gemini 3.5 Flash has built-in Computer Use. The model looks at a screenshot, decides what to do, and returns a function call like click(y=300, x=500). You execute that action on the device via ADB, take a new screenshot, and send it back. Repeat until the task is done.
This guide walks you through controlling an Android emulator using the mobile environment and the Python SDK.
Github Repository: https://github.com/google-gemini/gemini-android-computer-use-quickstart
What is Computer Use?#
Computer Use is a native tool in Gemini 3.5 Flash. You give the model a screenshot and a goal ("open Settings and turn on dark mode"). The model returns structured actions: taps, text input, swipes, app launches. Your code executes those actions on the target device.
It works like function calling. The model proposes actions, you execute them, you send back the result. The model stays in the loop through screenshots.
Gemini supports three Computer Use environments: browser for desktop web automation, mobile for mobile devices/emulators, and desktop for operating system-level control. This guide uses mobile.
Screenshot ──> Gemini 3.5 Flash ──> function_call
▲ │
│ ▼
└──────── Execute via ADB ◄──────────┘
Pseudocode#
Python
=
=
# Take initial screenshot and send first request
=
=
# Agent loop: execute actions, send results back
# click, type, open_app...
=
=
Supported actions (mobile environment)#
These are the actions the model can request when using environment: "mobile". Your code must handle each one.
| Action | Description | Arguments |
|---|---|---|
open_app |
Opens an app by name | app_name: str, intent: str (optional) |
click |
Tap a screen coordinate | y: int (0-999), x: int (0-999) |
type |
Type text | text: str, press_enter: bool (default false) |
long_press |
Long-press a coordinate | y: int (0-999), x: int (0-999), seconds: int (default 2) |
drag_and_drop |
Drag between two points | start_y, start_x, end_y, end_x |
press_key |
Press a key (home, back, enter...) | key: str |
go_back |
Navigate back | (none) |
wait |
Pause execution | seconds: int (default 1) |
list_apps |
List installed apps | (none) |
take_screenshot |
Capture the screen | (none) |
Coordinates are normalized to a 0-999 grid. (0, 0) is top-left, (999, 999) is bottom-right. Your bridge converts these to actual pixel coordinates based on the device resolution.
Setup#
No Android Studio GUI required. Run the setup script on your Mac to install the Android SDK, emulator, and create a virtual device from the terminal.
1. Run the setup script#
Install script link: https://github.com/google-gemini/gemini-android-computer-use-quickstart/blob/main/setup_emulator.sh
Bash
2. Install Python dependencies#
Bash
The Python agent script handles locating SDK paths and starting the emulator in the background automatically, so no additional manual environment variable exporting or terminal setup is required.
The agent loop#
Full working script agent.py. It automatically sets up the environment variables, launches the emulator in the background (if it isn't already running), waits for it to boot, and begins the Computer Use loop.
Python
=
=
= None
=
break
=
=
=
= + +
=
return
=
return
pass
=
=
=
return
pass
= +
, =
=
return
=
=
return
return ,
, =
= or
=
, =
=
, =
, =
, =
, =
=
=
=
return
return
return None
=
return
=
=
=
=
=
= None
= 0
+= 1
=
=
=
=
=
=
=
# auto approve safety decisions for demo
= True
=
=
break
=
=
break
return
=
=
How to run it#
Bash
# Set your API key
# Run the agent (starts the emulator automatically if needed)
Connecting to a Remote Device#
You can also target physical Android devices or remote cloud emulators instead of a local virtual device.
-
Enable USB/Wireless Debugging: On your target device, enable Developer Options and turn on USB Debugging or Wireless Debugging.
-
Connect via ADB: Use the
adb connectcommand to link to a remote device over TCP/IP:Bash
For details on setting up wireless debugging, refer to the official Android developer documentation on ADB over Wi-Fi.
-
Pass the Device ID to the Agent: Pass the remote device's connection string as the
device_idparameter to target it in the agent loop:Python
# Target a remote or cloud-hosted emulator
Next Steps & Developer Tips#
I hope this gets you started with Gemini 3.5 Flash Computer Use on mobile. Next steps can be:
- Supporting iOS / iPhone: The Gemini API's
mobileenvironment is platform-agnostic. The model outputs actions (clicks, swipes, types) on the same normalized0-999grid regardless of whether the device is Android or iOS. To target an iPhone or iOS Simulator, you only need to swap outADBBridgewith an iOS-compatible tool—such as Apple'ssimctlCLI for simulator control, Appium, or go-ios for physical devices. - Production Robustness: The Python bridge code provided here is synchronous and optimized for demonstration. For production use, you should implement robust retry logic for network drops, handle ADB disconnects gracefully, and execute operations asynchronously.
- Handling Safety Decisions: In real-world tasks (especially those modifying state or making payments), the model might flag action steps with a
safety_decisionrequesting confirmation. Ensure your production loop inspectsstep.argumentsfor safety flags and prompts the user before executing the action. See the Gemini API Computer Use Safety Guidelines for details.
Thanks for reading! If you have any questions or feedback, please let me know on Twitter or LinkedIn.