Science/Technology

How to Control Your Android Device Remotely via a Telegram Bot: Termux Guide

In 2026, the power of mobile hardware is often underutilized. Many users carry pocket-sized supercomputers capable of executing complex server scripts, compiling applications, and running background automation. A major trend in the Android developer community has been utilizing Termux—a terminal emulator and Linux environment app—alongside the Termux:API wrapper to interact directly with hardware components. By linking this local terminal to a **Telegram Bot**, you can remotely control your Android device from anywhere in the world without deploying a web server. This guide will show you how to build a serverless Python-based Telegram bot running inside Termux to manage commands, query device statistics, capture photos, and send location alerts with simple chat messages.

Quick Answer:

To control Android remotely via Telegram, install **Termux** and the **Termux:API** app, configure a Python script running `python-telegram-bot`, and authorize only your private Telegram user ID. Messages sent to the bot will invoke Termux commands (like `termux-camera-photo` or `termux-battery-status`) and reply with the outputs directly. For other Telegram utility guides, check the Telekit Science & Technology Directory.

Table of Contents

What is Termux & Termux:API?

Termux is a powerful terminal emulator for Android that installs a minimal Linux distribution. You can install packages like Python, Node.js, Git, and OpenSSH without needing root access on your phone. To interact with actual physical phone features—like the camera, GPS, clipboard, battery status, or SMS—you use the **Termux:API** extension, which provides command-line scripts that communicate with the Android OS.

By writing a Python script that polls for incoming Telegram messages, you can translate commands in your chat (e.g., /photo, /battery, or /gps) into system commands executed within Termux, returning the outputs (like images or location maps) directly to your chat window.

Show count:

Prerequisites and Installation Steps

To set up the bot, prepare your Android device and install the required applications:

1. Install Termux and Termux:API

Important: Do not install Termux from the Google Play Store as those versions are outdated and unsupported.

  • Download and install Termux from F-Droid.
  • Download and install the Termux:API application from F-Droid. Make sure both apps are installed from the same source to avoid signature mismatch errors.

2. Install Package Dependencies

Open Termux and run the following command to update your system repositories and install packages:

pkg update && pkg upgrade
pkg install termux-api python git -y

3. Install python-telegram-bot

Install the Python package wrapper for the Telegram Bot API:

pip install python-telegram-bot requests
---

Writing the Python Remote Control Bot

Create a directory for your bot and write the script to listen for incoming authorized commands:

mkdir ~/termux-bot && cd ~/termux-bot
nano bot.py

Paste the following Python script into bot.py:

import os
import subprocess
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes

TOKEN = "YOUR_TELEGRAM_BOT_TOKEN"
AUTHORIZED_CHAT_ID = 123456789  # Replace with your actual Chat ID


async def is_authorized(update: Update) -> bool:
    if update.message.chat_id != AUTHORIZED_CHAT_ID:
        await update.message.reply_text("Unauthorized access attempt blocked.")
        return False
    return True


async def battery(update: Update, context: ContextTypes.DEFAULT_TYPE):
    if not await is_authorized(update): return
    # Query Termux API for battery status
    result = subprocess.run(["termux-battery-status"], capture_output=True, text=True)
    await update.message.reply_text(f"🔋 Battery Status:
{result.stdout}")


async def photo(update: Update, context: ContextTypes.DEFAULT_TYPE):
    if not await is_authorized(update): return
    await update.message.reply_text("📸 Capturing photo...")
    # Capture photo and save to file
    subprocess.run(["termux-camera-photo", "-c", "0", "photo.jpg"])
    if os.path.exists("photo.jpg"):
        with open("photo.jpg", "rb") as f:
            await update.message.reply_photo(photo=f)
        os.remove("photo.jpg")
    else:
        await update.message.reply_text("Error: Photo capture failed.")


def main():
    app = Application.builder().token(TOKEN).build()
    app.add_handler(CommandHandler("battery", battery))
    app.add_handler(CommandHandler("photo", photo))
    print("Bot is polling...")
    app.run_polling()

if __name__ == "__main__":
    main()

Replace YOUR_TELEGRAM_BOT_TOKEN with the credentials from @BotFather, and AUTHORIZED_CHAT_ID with your account ID. Run the script using Python:

python bot.py
---

Crucial Security and Chat Authorization Rules

Granting terminal control of your mobile device to a bot is highly powerful but risky. If a malicious attacker discovers your bot’s username, they could run commands to steal photos, access location tracking, or extract text message details. You must secure your setup:

  • Hardcode Authorized IDs: Never write a bot that responds to any user. Explicitly check that `message.chat_id` matches your exact ID. Reject all other inputs immediately.
  • Turn Off Bot Search: In BotFather, configure your bot to disable group additions (`/setjoingroups` -> Disable) and limit inline search functions if they are not needed.
  • Use Low Permissions: Do not grant Termux permissions that you do not plan to use. If you do not need location tracking, avoid running `termux-location` or granting GPS access to the Termux app.
Command Termux API Tool What It Does
/battery termux-battery-status Returns charge state, temperature, percentage
/photo termux-camera-photo Takes a photo using rear/front camera
/location termux-location Fetches current GPS coordinates
/toast [text] termux-toast Displays a popup message on the phone's screen

Top 5 Remote Commands to Run

  • Remote Volume Control: You can adjust media volume levels using the command termux-volume music [volume_level]. Great for finding a misplaced phone.
  • Get Clipboard Text: Retrieve whatever text is currently copied on the device clipboard with termux-clipboard-get.
  • Send SMS Messages: Compose and send text messages programmatically via termux-sms-send -n [number] [message].
  • Text-to-Speech: Type a message and have your phone speak it out loud remotely using termux-tts-speak [message].

Frequently Asked Questions (FAQ)

Do I need to root my Android device to run this?

No! Termux and Termux:API operate within Android's user space, meaning all features listed above work on completely unrooted, standard Android phones.

Does the Termux app need to stay open in the background?

Yes, the Python script must remain running. To prevent Android from closing the app during sleep, pull down your notification tray, tap on the Termux notification, and select "Acquire WakeLock". Also disable battery optimization for Termux.

Can I run shell scripts or other binaries?

Yes, you can configure your bot to accept terminal arguments and run any standard CLI binaries, allowing you to run backup scripts, git syncs, or diagnostic scripts remotely.

How do I list my custom Telegram utility bot on Telekit?

If you have built an open-source bot or Telegram tool, click "Submit Link" on our homepage to have it verified and listed in the Science & Technology category.

Conclusion

By connecting a Telegram bot with the command-line capabilities of Termux, you transform your Android device into a remotely manageable server. This setup opens endless opportunities for automation, hardware diagnostics, and mobile productivity without requiring cloud hosting. Configure your authorized user ID, set up the WakeLock, and enjoy the convenience of managing your phone through a chat interface!

+ Add Telegram Group

Join Our Telegram Channel! 🚀

Stay updated with the latest Telegram groups and channels

Join on Telegram

Or scan the QR code

Telegram QR Code
⚡ Instant Updates 🔔 Latest Groups 💬 Community Chat

Loading community stats...

Search Telekit

🚀 Share & Earn 15 PTS

Complete the steps below to claim your reward instantly!

1 Copy Dynamic Post Text

Loading viral copy...

2 Share to Platform

Make sure to include your signature tag: #tk_...

3 Paste Shared Link

Anti-Cheat Policy: Posts must remain active and public. Deleting the shared post will trigger automatic checks that deduct the points from your profile.