Created
October 7, 2024 15:56
-
-
Save pyGuru123/559030025a040a1b36e6c4b92d4d1f02 to your computer and use it in GitHub Desktop.
Python code to interact with android using termux and termux-api package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import json | |
def termux_battery_status(): | |
# Call the termux-battery-status command | |
result = subprocess.run(['termux-battery-status'], stdout=subprocess.PIPE) | |
battery_info = json.loads(result.stdout.decode('utf-8')) | |
return battery_info | |
def termux_get_location(): | |
# Call the termux-location command | |
result = subprocess.run(['termux-location'], stdout=subprocess.PIPE) | |
location_info = json.loads(result.stdout.decode('utf-8')) | |
return location_info | |
def termux_send_sms(phone_number, message): | |
# Call the termux-sms-send command | |
subprocess.run(['termux-sms-send', '-n', phone_number, message]) | |
print(f"Message sent to {phone_number}") | |
def main(): | |
print("Choose an option:") | |
print("1. Check Battery Status") | |
print("2. Get Current Location") | |
print("3. Send SMS") | |
choice = input("Enter your choice: ") | |
if choice == '1': | |
battery_status = termux_battery_status() | |
print(f"Battery Status: {battery_status}") | |
elif choice == '2': | |
location = termux_get_location() | |
print(f"Location: {location}") | |
elif choice == '3': | |
phone_number = input("Enter the phone number: ") | |
message = input("Enter the message: ") | |
termux_send_sms(phone_number, message) | |
else: | |
print("Invalid choice. Please try again.") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment