Skip to content

FinalScave/AndroidClipboardSkill

Repository files navigation

AndroidClipboardSkill

A reusable agent skill for setting Android device clipboard text through ADB, including robust fallback handling for Android versions where direct clipboard shell commands are unavailable.

This repository packages an installable skill under android-clipboard-skill/ and keeps the Java helper source at the repository root for maintenance.

Features

  • Sets clipboard text on a connected Android device or emulator through ADB.
  • Supports multi-line text through stdin, which is useful for commit messages, logs, commands, and generated output.
  • Uses a prebuilt dex helper at runtime, so ordinary clipboard writes only need ADB.
  • Resolves ADB from --adb, $ADB, PATH, common Android SDK paths, Homebrew, and /usr/local/bin.
  • Runs the helper through app_process to set a real ClipData clipboard payload.
  • Automatically removes the temporary dex pushed to /data/local/tmp.

Repository Layout

AndroidClipboardSkill/
├── android-clipboard-skill/
│   ├── SKILL.md
│   ├── agents/openai.yaml
│   ├── bin/set-android-clipboard.dex
│   └── scripts/
│       ├── build_helper_dex.sh
│       └── set_android_clipboard.sh
└── src/main/java/com/agenttools/androidclipboard/SetAndroidClipboard.java

Installation

Copy or install the android-clipboard-skill/ directory into your agent's skill directory.

For manual use, run commands from the repository root or from inside android-clipboard-skill/.

Usage

Set a simple string:

android-clipboard-skill/scripts/set_android_clipboard.sh "text to copy"

Set multi-line text:

printf '%s' "$text" | android-clipboard-skill/scripts/set_android_clipboard.sh --stdin

Use a specific device:

android-clipboard-skill/scripts/set_android_clipboard.sh \
  --device "$ANDROID_SERIAL" \
  --stdin < message.txt

Use a specific ADB binary:

android-clipboard-skill/scripts/set_android_clipboard.sh \
  --adb "/path/to/adb" \
  --stdin < message.txt

Set a custom clipboard label:

printf '%s' "$text" | android-clipboard-skill/scripts/set_android_clipboard.sh \
  --label "Generated message" \
  --stdin

Agent Workflow

Agents should prefer the runtime script and the prebuilt dex:

printf '%s' "$text" | android-clipboard-skill/scripts/set_android_clipboard.sh --stdin

If ADB is not in PATH, agents should resolve it from the host environment and pass --adb /path/to/adb. The script also searches common locations automatically:

  • $ADB
  • $ANDROID_HOME/platform-tools/adb
  • $ANDROID_SDK_ROOT/platform-tools/adb
  • ~/Library/Android/sdk/platform-tools/adb
  • ~/Android/Sdk/platform-tools/adb
  • /opt/homebrew/bin/adb
  • /usr/local/bin/adb

Rebuilding the Dex

The bundled dex should be used for normal runtime writes. Rebuild only when SetAndroidClipboard.java changes or the dex is missing:

android-clipboard-skill/scripts/build_helper_dex.sh

Rebuilding requires:

  • javac
  • Android SDK android.jar
  • Android SDK build-tools d8

The generated file is written to:

android-clipboard-skill/bin/set-android-clipboard.dex

How It Works

Modern Android clipboard APIs require a real ClipData Parcelable. Direct shell calls such as service call clipboard ... s16 ... are not reliable for setting text on modern Android versions.

The helper dex:

  • receives base64-encoded text to avoid shell quoting issues,
  • gets the clipboard binder service through android.os.ServiceManager,
  • creates ClipData.newPlainText(...),
  • calls IClipboard.setPrimaryClip(...) by reflection,
  • runs through app_process so Android framework runtime initialization is available.

Troubleshooting

Check connected devices:

adb devices

If multiple devices are connected, pass --device SERIAL.

If ADB is not found, pass --adb /path/to/adb or set ADB.

If clipboard writing fails on a device, confirm USB debugging is enabled and the device is authorized.

About

A reusable agent skill for setting Android device clipboard text through ADB, including robust fallback handling for Android versions without direct clipboard shell command support.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors