# Termux Flask Development Setup Guide ## SMS Campaign Manager on Android ### Prerequisites - Termux installed on Android - Termux:API app installed (for Android API access) - SSH access configured (optional, for remote development) ### Initial Setup #### 1. Update Termux Packages ```bash pkg update && pkg upgrade ``` #### 2. Install Required System Packages ```bash # Install Python and development tools pkg install python python-pip # Install Node.js (if needed for npm packages) pkg install nodejs # Install which command (useful for debugging) pkg install which # Install Termux API package pkg install termux-api ``` ### Project Setup #### 1. Create Project Directory Structure ```bash mkdir -p ~/projects/sms-campaign-manager cd ~/projects/sms-campaign-manager ``` #### 2. Install Python Dependencies ```bash pip install flask werkzeug requests ``` #### 3. Create the Flask Application Create `app.py` with the following content: ```python from flask import Flask, jsonify, render_template_string import subprocess import json app = Flask(__name__) @app.route('/') def index(): return render_template_string('''
Server IP: 10.0.0.193:5000
Environment: Termux on Android
{json.dumps(battery_data, indent=2)}
"""
except Exception as e:
return f"{str(e)}"
@app.route('/notification')
def notification():
try:
subprocess.run(['termux-notification', '--title', 'Flask Test', '--content', 'Hello from SMS Campaign Manager!'], capture_output=True, text=True)
return f"""
Check your Android notifications.
""" except Exception as e: return f"{str(e)}"
if __name__ == '__main__':
print("🚀 Starting SMS Campaign Manager on Termux...")
print("📱 Device IP: 10.0.0.193")
print("🌐 Access from Ubuntu: http://10.0.0.193:5000")
app.run(host='0.0.0.0', port=5000, debug=True)
```
### Running the Application
#### 1. Start the Flask Server
```bash
cd ~/projects/sms-campaign-manager
python app.py
```
#### 2. Access the Application
- **From Android device:** http://127.0.0.1:5000
- **From Ubuntu/network:** http://10.0.0.193:5000 (replace with your device IP)
- **From SSH:** Access via the device's network IP
### Features Implemented
1. **Web Interface**: Clean, responsive HTML interface
2. **Battery Status API**: Uses `termux-battery-status` to display device battery info
3. **Notification API**: Sends test notifications using `termux-notification`
4. **Network Access**: Configured to accept connections from any IP (0.0.0.0)
### Useful Commands
#### Check if server is running
```bash
ps aux | grep python
```
#### Find your device IP
```bash
ifconfig wlan0 | grep inet
# or
ip addr show wlan0
```
#### Kill existing Flask processes
```bash
pkill -f "python app.py"
```
#### Run in background with nohup
```bash
nohup python app.py > flask.log 2>&1 &
```
#### View logs
```bash
tail -f flask.log
```
### SSH Access from Ubuntu
If you want to develop from your Ubuntu machine:
```bash
# From Ubuntu, SSH into Termux
ssh android-dev
# Navigate to project
cd ~/projects/sms-campaign-manager
# Edit files with nano or vim
nano app.py
```
### Troubleshooting
#### Port Already in Use
```bash
# Find process using port 5000
lsof -i :5000
# Kill the process
kill -9