PHP Classes

PHP Termux API: Control Android device using Termux application

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 61%Total: 772 All time: 4,390 This week: 64Up
Version License PHP version Categories
termuxapi 1.0GNU General Publi...5PHP 5, System information, Wireless a..., A..., G..., C..., H...
Description 

Author

This class can control Android device using Termux application.

It can execute the termux terminal emulator application from the command line and run several types of commands to control the several aspects of an Android mobile phone or table. Currently it can:

- Check the battery status
- Get the camera details
- Take a picture
- Copy text from and to the clipboard
- Retrieve user contact list
- Download files from a given URL
- Get the device location from the GPS or other device
- Send notifications to the device user
- Open URLs in the device default browser
- Share content file
- Send SMS message
- Get received SMS messages
- Get the phone information
- Show an Android toast notification
- Get the list of TTS (Text to Speach) devices
- Play text as speech
- Vibrate
- Scan WiFi devices
- Get the WiFi connection details

Innovation Award
PHP Programming Innovation award nominee
February 2017
Number 2


Prize: One big elePHPant Plush Mascott
Termux is a Android application that allows running applications from a Linux shell. PHP can be run from Termux too.

This class provides a wrapper to access to services provides by the Termux API app to access and control several aspects of an Android device.

Manuel Lemos
Picture of Luis Martinez Ulloa
  Performance   Level  
Name: Luis Martinez Ulloa is available for providing paid consulting. Contact Luis Martinez Ulloa .
Classes: 12 packages by
Country: Peru Peru
Age: 52
All time rank: 3991 in Peru Peru
Week rank: 146 Up1 in Peru Peru Equal
Innovation award
Innovation award
Nominee: 5x

Example

<?php

//wide test
// lsmartinez@gmail.com
$photo = "photo.jpg";
$dwldfile = "http://cl1.php.net/get/php_manual_en.html.gz/from/this/mirror";
$url = "http://www.php.net/";
//please change this variables before running this example, to adapt to your
//language and own phone number.
$test = "prueba desde php 7";
//your phone
$phone = "999999999";
$lang = "es";
$notimpl = "no implementado aun.";

//---------------------------------------------------------------------------

if (file_exists("termuxapi.php")) {
    require_once
'termuxapi.php';

   
$termux = new termuxapi();
   
$msg = " ";
   
$title = "Web Test";
    if (isset(
$_GET["f"])) {
        switch (
$_GET['f']) {
            case
'1':
               
$title = "Location";
               
$msg = $termux->location();
                break;
            case
'2':
               
$title = "Battery";
               
$msg = $termux->battery_status();
                break;
            case
'3':
               
$title = "cam info";
               
$msg = $termux->camera_info();
                break;
            case
'4':
               
$title = "take picture";
               
$termux->camera_photo($photo);
               
$msg = "<img src='$photo'>";
                break;
            case
'5':
               
$title = "get clipbd";
               
$msg = $termux->clipboard_get();
                break;
            case
'6':
               
$title = "set clipbd";
               
$termux->clipboard_set($test);
                break;
            case
'7':
               
$title = "contacts";
               
$msg = $termux->contact_list();
                break;
            case
'8':
               
$title = "download";
               
$termux->download($dwldfile);
                break;
            case
'9':
               
$title = "notify";
               
$termux->notification($test);
                break;
            case
'10':
               
$title = "open url";
               
$termux->open_url($url);
                break;
            case
'11':
               
$title = "share";
               
$termux->share($photo);
                break;
            case
'12':
               
$title = "sms inbox";
               
$msg = $termux->sms_inbox();
                break;
            case
'13':
               
$title = "sms send";
               
$termux->sms_send($phone, $test);
                break;
            case
'14':
               
$title = "phone info";
               
$msg = $termux->telephony_deviceinfo();
                break;
            case
'15':
               
$title = "toast";
               
$termux->toast($test);
                break;
            case
'16':
               
$title = "tts engines";
               
$msg = $termux->tts_engines();
                break;
            case
'17':
               
$title = "tts speak";
               
$termux->tts_speak($test, "", $lang);
                break;
            case
'18':
               
$title = "vibrate";
               
$termux->vibrate();
                break;
            case
'19':
               
$title = "wifi info";
               
$msg = $termux->wifi_connectioninfo();
                break;
            case
'20':
               
$title = "wifi scan";
               
$msg = $termux->wifi_scaninfo();
                break;

            default:
               
$msg = $notimpl;
                break;
        }
        if (
strstr("{[", substr($msg, 0, 1)) !== false) {
           
$msg = "<pre>$msg</pre>";
        }
    }
}
$selfie = basename(__FILE__);
?><!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <meta name="description" content="testing of termux:API from php">
        <meta name="author" content="">
        <title>Termux:API <?= $title ?></title>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
        <style>
            p > img {
                width: 100%;
            }

            body {
                padding-top: 70px;
                padding-bottom: 30px;
            }

        </style>
    </head>

    <body>

        <nav class="navbar navbar-inverse navbar-fixed-top">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="<?= $selfie ?>">Termux:API <?= $title ?></a>
                </div>
                <div id="navbar" class="navbar-collapse collapse">
                </div>
            </div>
        </nav>

        <div class="container theme-showcase" role="main">

            <p>
                <a class="btn btn-default" href="<?= $selfie ?>?f=1"><span class="fa fa-map-marker"></span><span class="fa fa-question"></span></a>
                <a class="btn btn-primary" href="<?= $selfie ?>?f=2"><span class="fa fa-battery-4"></span><span class="fa fa-question"></span></a>
                <a class="btn btn-success" href="<?= $selfie ?>?f=3"><span class="fa fa-camera"></span><span class="fa fa-question"></span></a>
                <a class="btn btn-info" href="<?= $selfie ?>?f=4"><span class="fa fa-camera"></span><span class="fa fa-flash"></span></a>
                <a class="btn btn-warning" href="<?= $selfie ?>?f=5"><span class="fa fa-copy"></span></a>
                <a class="btn btn-danger" href="<?= $selfie ?>?f=6"><span class="fa fa-paste"></span></a>
                <a class="btn btn-default" href="<?= $selfie ?>?f=7"><span class="fa fa-users"></span></span><span class="fa fa-list"></span></a>
                <a class="btn btn-primary" href="<?= $selfie ?>?f=8"><span class="fa fa-download"></span></a>
                <a class="btn btn-success" href="<?= $selfie ?>?f=9"><span class="fa fa-flag"></span></a>
                <a class="btn btn-info" href="<?= $selfie ?>?f=10"><span class="fa fa-globe"></span></a>
                <a class="btn btn-warning" href="<?= $selfie ?>?f=11"><span class="fa fa-share-alt"></span></a>
                <a class="btn btn-danger" href="<?= $selfie ?>?f=12"><span class="fa fa-envelope-o"></span></span><span class="fa fa-list"></span></a>
                <a class="btn btn-default" href="<?= $selfie ?>?f=13"><span class="fa fa-envelope"></span></a>
                <a class="btn btn-primary" href="<?= $selfie ?>?f=14"><span class="fa fa-mobile-phone"></span><span class="fa fa-question"></span></a>
                <a class="btn btn-success" href="<?= $selfie ?>?f=15"><span class="fa fa-comment"></span></a>
                <a class="btn btn-info" href="<?= $selfie ?>?f=16"><span class="fa fa-volume-off"></span><span class="fa fa-question"></span></a>
                <a class="btn btn-warning" href="<?= $selfie ?>?f=17"><span class="fa fa-user"></span><span class="fa fa-volume-up"></span></a>
                <a class="btn btn-danger" href="<?= $selfie ?>?f=18"><span class="fa fa-mobile-phone"></span><span class="fa fa-bomb"></span></a>
                <a class="btn btn-default" href="<?= $selfie ?>?f=19"><span class="fa fa-wifi"></span><span class="fa fa-area-chart"></span></a>
                <a class="btn btn-primary" href="<?= $selfie ?>?f=20"><span class="fa fa-wifi"></span><span class="fa fa-list"></span></a>
            </p>

            <p>
                <?= $msg ?>
</p>


        </div>
        <script src="http://code.jquery.com/jquery-3.1.1.min.js" type="text/javascript"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    </body>
</html>


Screenshots (5)  
  • 02clip04.jpg
  • 02clip04b.jpg
  • 03test05.png
  • 03test06.jpg
  • 03test07.jpg
  Files folder image Files (9)  
File Role Description
Accessible without login Plain text file clipshow.php Example Clipboard Example
Accessible without login Plain text file location.php Example Location Example
Plain text file termuxapi.php Class The class
Accessible without login Plain text file test.php Example Web test all methods

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:772
This week:0
All time:4,390
This week:64Up
User Ratings User Comments (2)
 All time
Utility:89%StarStarStarStarStar
Consistency:85%StarStarStarStarStar
Documentation:-
Examples:78%StarStarStarStar
Tests:-
Videos:-
Overall:61%StarStarStarStar
Rank:1099
 
Great use of android features
7 years ago (Eric Wambugu)
65%StarStarStarStar
Thats a very good class ;-)
7 years ago (José Filipe Lopes Santos)
70%StarStarStarStar