26

termux-api让你的Termux访问手机系统功能

 3 years ago
source link: https://www.lujun9972.win/blog/2019/07/26/termux-api%E8%AE%A9%E4%BD%A0%E7%9A%84termux%E8%AE%BF%E9%97%AE%E6%89%8B%E6%9C%BA%E7%B3%BB%E7%BB%9F%E5%8A%9F%E8%83%BD/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

termux-api让你的Termux访问手机系统功能

Termux可以让你的手机变成一台Linux服务器,这很好玩。但是另一方面手机拥有某些特殊的能力是一般Linux服务器所不具备的,比如打电话、发短信、照相等。

Termux 默认可以调用的手机功能不多,只有两个API:

termux-open $file打开手机存储上的文件 termux-open-url $url调用浏览器访问URL

而借助 Termux-api 我们可以让Termux调用更多手机上的系统功能,从而实现更加强大的脚本。

  1. 在Google Player Store上安装好 termux-api(或者从apksfull上下载apk包)
  2. 在 Termux 中运行 pkg install termux-api 安装 termux-api

API说明

termux-api提供了很多以 termux- 开头的命令,执行相应的命令就能调用手机对应的系统功能,而且这些命令以Json的格式输出执行结果。

从命令名中我们可以很容易推测出命令的作用,而且所有命令都能通过 -h 选项来查询命令的使用方法。

访问电池信息termux-battery-status 设置屏幕亮度termux-battery-status ${brightness} 获取相机信息termux-camera-info 调用相机照相termux-camera-photo ${photo_file} 获取剪贴板信息termux-clipboard-get 设置剪贴板信息termux-clipboard-set 获取通讯录信息termux-contact-list 手机下载文件termux-download [-t ${title}] [-d ${description}] ${URL} 获取手机信息termux-info/termux-telephony-cellinfo/termux-telephony-deviceinfo 获取手机位置termux-localtion 手机媒体扫描,并添加文件到媒体库中termux-media-scan [-r] ${file_or_directory} 手机媒体播放termux-media-player 手机录音termux-microphone-record 拨打电话termux-telelphony-call ${number} 显示系统提醒termux-notification [options] 通过手机分享功能分享指定文件termux-share [-a action] [-c content-type] [-d] [-t title] [file] 振动设备termux-vibrate [-d duration] [-f] 开关LED灯termux-torch [on | off] 语音读出文本termux-tts-speak [-e engine] [-l language] [-n region] [-v variant] [-p pitch] [-r rate] [-s stream] [text-to-speak] 设置墙纸termux-wallpaper cmd [args] 显示当前wifi信息termux-wifi-connectioninfo 扫描wifitermux-wifi-scaninfo -h 开关wifitermux-wifi-enable [true | false] 定时运行Termux脚本termux-job-scheduler [options] 在手机上显示消息termux-toast [-b bgcolor] [-c color] [-g gravity] [-s] [text] 在手机上显示图形输入框termux-dialog widget [options] 其中,widget的种类可以用 termux-dialog -l 来列出

Python包

由于Termux-api如此有用,以至于有人做了一个Python包来对其进行封装:termux_python


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK