# Basic Source: https://docs.gbox.ai/android/basic [GBOX](https://gbox.ai) provides cloud-based Android automation testing without the need to purchase, configure, or maintain any Android devices. GBOX supports both `virtual machines` and `physical devices`, letting you focus on testing: * **No Device Management** - Eliminate hardware procurement, system configuration, and device maintenance hassles * **Ready to Use** - Get clean Android testing environments in seconds * **Flexible Options** - Choose between virtual machines or physical devices based on your testing needs * **Auto Scaling** - Run multiple tests in parallel without hardware limitations 1. Go to [GBOX AI](http://gbox.ai) 2. Copy your API Key 3. Paste your GBOX API Key into your `env` file ```bash .env theme={null} GBOX_API_KEY=gbox-****** ``` Install gbox-sdk and other dependencies by running the following command in your terminal. ```bash Typescript icon="https://cdn.worldvectorlogo.com/logos/typescript.svg" theme={null} npm install gbox-sdk dotenv typescript tsx @types/node ``` ```bash Python icon="https://cdn.worldvectorlogo.com/logos/python-5.svg" theme={null} # Set up a virtual environment python3 -m venv venv source venv/bin/activate pip install gbox-sdk python-dotenv ``` Create a basic Android box by running the following code. ```typescript Typescript icon="https://cdn.worldvectorlogo.com/logos/typescript.svg" theme={null} import GboxSDK from "gbox-sdk"; import * as dotenv from "dotenv"; dotenv.config(); const gboxSDK = new GboxSDK({ apiKey: process.env["GBOX_API_KEY"], // This is the default and can be omitted }); async function main() { const box = await gboxSDK.create({ type: "android" }); console.log(`Android box created: ${box.data.id}`); // take a screenshot of the box await box.action.screenshot({ path: "screenshot.png", }); // terminate the box await box.terminate(); console.log("Box terminated"); } main(); ``` ```python Python icon="https://cdn.worldvectorlogo.com/logos/python-5.svg" theme={null} import os from dotenv import load_dotenv from gbox_sdk import GboxSDK # Load environment variables from .env file load_dotenv() def main(): api_key = os.getenv("GBOX_API_KEY") gbox = GboxSDK(api_key=api_key) box = gbox.create(type="android") print(f"Android box created: {box.data.id}") # take a screenshot of the box box.action.screenshot(path="screenshot.png") # terminate the box box.terminate() print("Box terminated") if __name__ == "__main__": main() ``` Run the box by running the following command in your terminal. ```bash Typescript icon="https://cdn.worldvectorlogo.com/logos/typescript.svg" theme={null} npx tsx index.ts ``` ```bash Python icon="https://cdn.worldvectorlogo.com/logos/python-5.svg" theme={null} python main.py ``` Explore the complete Android API reference to discover all available operations and features. # Install app Source: https://docs.gbox.ai/android/install-app [GBOX](https://gbox.ai) lets you easily install Android applications on cloud-based devices without needing physical hardware. You can install apps from APK files, URLs, or local files, making app testing and development seamless: * **Flexible Installation** - Install apps from URLs, local APK files, or app stores * **Instant Access** - Install and launch apps in seconds on clean Android environments * **No Setup Required** - Skip device configuration and app sideloading complexities * **Live Testing** - View and interact with installed apps through live browser sessions 1. Go to [GBOX AI](http://gbox.ai) 2. Copy your API Key 3. Paste your GBOX API Key into your `env` file ```bash .env theme={null} GBOX_API_KEY=gbox-****** ``` Install gbox-sdk and other dependencies by running the following command in your terminal. ```bash Typescript icon="https://cdn.worldvectorlogo.com/logos/typescript.svg" theme={null} npm install gbox-sdk dotenv typescript tsx @types/node ``` ```bash Python icon="https://cdn.worldvectorlogo.com/logos/python-5.svg" theme={null} # Set up a virtual environment python3 -m venv venv source venv/bin/activate pip install gbox-sdk python-dotenv ``` Create a basic Android box by running the following code. ```typescript Typescript icon="https://cdn.worldvectorlogo.com/logos/typescript.svg" highlight={16-19} theme={null} import GboxSDK from "gbox-sdk"; import * as dotenv from "dotenv"; dotenv.config(); const gboxSDK = new GboxSDK({ apiKey: process.env["GBOX_API_KEY"], // This is the default and can be omitted }); async function main() { const box = await gboxSDK.create({ type: "android" }); console.log(`Android box created: ${box.data.id}`); // install markor (a open source markdown editor) const app = await box.app.install({ apk: "https://github.com/gsantner/markor/releases/download/v2.14.1/net.gsantner.markor-v158-2.14.1-flavorDefault-release.apk" }) // open the app await app.open() // you can also install an apk from your local machine // const app = await box.app.install({ // apk: "/path/to/your/app.apk" // }) const liveView = await box.liveView() console.log(`Open the following URL in your browser to see the live view: ${liveView.url}`); } main(); ``` ```python Python icon="https://cdn.worldvectorlogo.com/logos/python-5.svg" highlight={19} theme={null} import os from dotenv import load_dotenv from gbox_sdk import GboxSDK # Load environment variables from .env file load_dotenv() def main(): api_key = os.getenv("GBOX_API_KEY") gbox = GboxSDK(api_key=api_key) box = gbox.create(type="android") print(f"Android box created: {box.data.id}") # install markor (a open source markdown editor) app = box.app.install( apk="https://github.com/gsantner/markor/releases/download/v2.14.1/net.gsantner.markor-v158-2.14.1-flavorDefault-release.apk" ) # open the app app.open() # you can also install an apk from your local machine # app = box.app.install({ # "apk": "/path/to/your/app.apk" # }) live_view = box.live_view() print(f"Open the following URL in your browser to see the live view: {live_view.url}") if __name__ == "__main__": main() ``` Run the box by running the following command in your terminal. ```bash Typescript icon="https://cdn.worldvectorlogo.com/logos/typescript.svg" theme={null} npx tsx index.ts ``` ```bash Python icon="https://cdn.worldvectorlogo.com/logos/python-5.svg" theme={null} python main.py ``` Explore the complete Android API reference to discover all available operations and features. # Live View Source: https://docs.gbox.ai/android/live-view Live View provides real-time remote access to Android devices, allowing you to directly control and interact with cloud-based Android devices through your browser. ## Get Started 1. Go to [GBOX AI](http://gbox.ai) 2. Copy your API Key 3. Paste your GBOX API Key into your `env` file ```bash .env theme={null} GBOX_API_KEY=gbox-****** ``` Install gbox-sdk and other required dependencies by running the following command in your terminal. ```bash Typescript icon="https://cdn.worldvectorlogo.com/logos/typescript.svg" theme={null} npm install gbox-sdk dotenv typescript tsx @types/node open ``` ```bash Python icon="https://cdn.worldvectorlogo.com/logos/python-5.svg" theme={null} # Set up a virtual environment python3 -m venv venv source venv/bin/activate pip install gbox-sdk python-dotenv ``` Create a Live View box by creating the following code file. ```typescript Typescript icon="https://cdn.worldvectorlogo.com/logos/typescript.svg" highlight={42} theme={null} import GboxSDK, { AndroidBoxOperator } from "gbox-sdk"; import * as dotenv from "dotenv"; import open from "open"; dotenv.config(); const gboxSDK = new GboxSDK({ apiKey: process.env["GBOX_API_KEY"], // This is the default and can be omitted }); let currentBox: AndroidBoxOperator | null = null; async function gracefulShutdown() { if (currentBox) { console.log("Shutting down program, deleting Android box..."); try { await currentBox.terminate(); console.log("Box successfully terminated"); } catch (error) { console.log(`Error terminating box: ${error}`); } } process.exit(0); } // Listen for SIGINT signal (Ctrl+C) process.on("SIGINT", gracefulShutdown); process.on("SIGTERM", gracefulShutdown); async function main() { try { console.log("\nAndroid Box Manager Started\n"); console.log("Creating Android box..."); const box = await gboxSDK.create({ type: "android" }); currentBox = box; console.log("Android box created successfully!"); console.log(`Box ID: ${box.data.id}`); console.log("Getting live view..."); const liveView = await box.liveView(); console.log("Live view is ready!"); console.log(`View URL: ${liveView.url}`); console.log("Opening browser..."); console.log( `You can try operate the android box in the browser, and then press Ctrl+C to stop and terminate box\n` ); await open(liveView.url, { wait: true, }); // Keep the program running, waiting for SIGINT signal await new Promise(() => {}); } catch (error) { console.log(`An error occurred: ${error}`); if (currentBox) { await gracefulShutdown(); } process.exit(1); } } main(); ``` ```python Python icon="https://cdn.worldvectorlogo.com/logos/python-5.svg" highlight={44} theme={null} import os import signal import sys import webbrowser from dotenv import load_dotenv from gbox_sdk import GboxSDK # Load environment variables from .env file load_dotenv() current_box = None def graceful_shutdown(signum, frame): global current_box if current_box: print("Shutting down program, deleting Android box...") try: current_box.terminate() print("Box successfully terminated") except Exception as error: print(f"Error terminating box: {error}") sys.exit(0) # Listen for SIGINT signal (Ctrl+C) signal.signal(signal.SIGINT, graceful_shutdown) signal.signal(signal.SIGTERM, graceful_shutdown) def main(): global current_box try: print("\nAndroid Box Manager Started\n") api_key = os.getenv("GBOX_API_KEY") gbox = GboxSDK(api_key=api_key) print("Creating Android box...") box = gbox.create(type="android") current_box = box print("Android box created successfully!") print(f"Box ID: {box.data.id}") print("Getting live view...") live_view = box.live_view() print("Live view is ready!") print(f"View URL: {live_view.url}") print("Opening browser...") print( "You can try operate the android box in the browser, and then press Ctrl+C to stop and terminate box\n" ) webbrowser.open(live_view.url) # Keep the program running, waiting for SIGINT signal while True: pass except Exception as error: print(f"An error occurred: {error}") if current_box: graceful_shutdown(None, None) sys.exit(1) if __name__ == "__main__": main() ``` Run the Live View box by running the following command in your terminal. ```bash Typescript icon="https://cdn.worldvectorlogo.com/logos/typescript.svg" theme={null} npx tsx index.ts ``` ```bash Python icon="https://cdn.worldvectorlogo.com/logos/python-5.svg" theme={null} python main.py ``` ## Embed Live View in your website You can embed Live View in your website by using the following code. ```html theme={null}