termux

package module
v0.0.0-...-fda8ef8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

README

go-termux

API Documentation

Golang wrapper for termux:API. This package calls termux:API methods directly so that this package would work without termux-api package installed.

Examples

Acquires the current battery percentage
package main

import (
        "fmt"

        tm "github.com/eternal-flame-AD/go-termux"
)

func main() {
        if stat, err := tm.BatteryStatus(); err != nil {
                panic(err)
        } else {
                fmt.Printf("The current battery percentage is %d%%.\n", stat.Percentage)
        }
}
Sets current clipboard content
package main

import tm "github.com/eternal-flame-AD/go-termux"

func main() {
    if err := tm.ClipboardSet("ummmm"); err != nil {
        panic(err)
    }
}
Displays a short toast
package main

import (
        tm "github.com/eternal-flame-AD/go-termux"
)

func main() {
        if err := tm.Toast("Hello World!", tm.ToastOption{
                FontColor: "#FF0000",
                Position:  tm.Top,
                Short:     true,
                BGColor:   "#00FF00",
        }); err != nil {
                panic(err)
        }
}

Documentation

Overview

Package termux implements termux:API calls and wraps them into golang function calls.

Example:
package main

import tm "github.com/eternal-flame-AD/go-termux"

func main() {
	if err := tm.ClipboardSet("ummmm"); err != nil {
		panic(err)
	}
}

We call termux:API methods directly so that this package would work without termux-api package installed.

Index

Constants

This section is empty.

Variables

View Source
var GlobalTimeout = 15 * time.Second

GlobalTimeout The global timeout to non-persistent and non-time-consumingn operations

Functions

func AudioStreamVolume

func AudioStreamVolume(name string, volume int) error

AudioStreamVolume sets the volume of a given audio stream name

func Brightness

func Brightness(level uint8) error

Brightness sets the current brightness level from 0 to 255

func BrightnessAuto

func BrightnessAuto() error

BrightnessAuto sets the current brightness to auto

func ClipboardGet

func ClipboardGet() (string, error)

ClipboardGet gets the current content of the clipboard

func ClipboardSet

func ClipboardSet(val string) error

ClipboardSet sets the clipboard to the given value

func Dialog

func Dialog() error

Dialog pops up a dialog on the device Not implemented yet as the original api does not work on mmy device

func Download

func Download(desc string, title string, url string) error

Download calls the system download manager to download an URL

func Fingerprint

func Fingerprint() error

Fingerprint uses the fingerprint sensor on the device for authentication Not implemented as the original API does not work on my device

func Notification

func Notification(id string, opt NotificationOpt) error

Notification creates a new notification with the given id and options

func NotificationRemove

func NotificationRemove(id string) error

NotificationRemove removes the notification with the given id

func SMSSend

func SMSSend(numbers []string, text string) error

SMSSend sends a text message to the given recipient numbers

func Sensor

func Sensor(ctx context.Context, opt SensorWatchOpt) (<-chan []byte, error)

Sensor starts a sensor watch in a given context and options returns raw data bytes encooded with JSON

func SensorList

func SensorList() ([]string, error)

SensorList acquires a list of available sensors on the device

func Share

func Share(title string, data []byte, contentType string, useDefault bool, actionType ShareType) error

Share shares raw data bytes with the given content type, useDefault determines whether to use the default app if availables

func ShareFile

func ShareFile(title string, path string, useDefault bool, actionType ShareType) error

ShareFile shares a file with MIME type determined by the file extension, useDefault determines whether to use the default app if availables

func TakePhoto

func TakePhoto(cameraID string, outfile string) error

TakePhoto uses the device camera to take a photo and save the result to outfile cameraID is the id of the camera specified by the return of CameraInfo

func Toast

func Toast(text string, opts ToastOption) error

Toast creates a toast on the device

func TorchEnable

func TorchEnable(enabled bool) error

TorchEnable sets the current state of the device flashlight

func UpdatedLocation

func UpdatedLocation(ctx context.Context, provider LocationProvider) (<-chan struct {
	Location *LocationRecord
	Error    error
}, error)

UpdatedLocation acquires the real-time location of the device from a channel

func Viberate

func Viberate(ms int, force bool) error

Viberate creates a viberation on the device, force means whether to viberate even if the device is set to silent mode

func WallpaperFile

func WallpaperFile(path string, lockscreen bool) error

WallpaperFile sets the current wallpaper, main screen if lockscreen is false

func WallpaperURL

func WallpaperURL(url string, lockscreen bool) error

WallpaperURL sets the current wallpaper, main screen if lockscreen is false

func WifiEnable

func WifiEnable(enabled bool) error

WifiEnable sets the current enabled state of the device wifi

Types

type AudioInfoResponse

type AudioInfoResponse struct {
	JavaOutputSampleRate       string `json:"PROPERTY_OUTPUT_SAMPLE_RATE"`
	JavaOutputFramesPerBuffer  string `json:"PROPERTY_OUTPUT_FRAMES_PER_BUFFER"`
	AudioTrackOutputSampleRate int    `json:"AUDIOTRACK_NATIVE_OUTPUT_SAMPLE_RATE"`
	BluetoothA2DP              bool   `json:"BLUETOOTH_A2DP_IS_ON"`
	WiredHeadsetConnected      bool   `json:"WIREDHEADSET_IS_CONNECTED"`
}

AudioInfoResponse represents the current audio stream status

func AudioInfo

func AudioInfo() (*AudioInfoResponse, error)

AudioInfo acquires the corrent audio info

type AudioStreamState

type AudioStreamState struct {
	Name      string `json:"stream"`
	Volume    int    `json:"volume"`
	MaxVolume int    `json:"max_volume"`
}

AudioStreamState represents the volume info of an audio stream

func AudioStreams

func AudioStreams() ([]AudioStreamState, error)

AudioStreams acquires all audio stream volume info from the device

type BatteryStatusResponse

type BatteryStatusResponse struct {
	Health      string  `json:"health"`
	Percentage  int     `json:"percentage"`
	Plugged     string  `json:"plugged"`
	Status      string  `json:"status"`
	Temperature float64 `json:"temperature"`
}

BatteryStatusResponse represents the current battery status

func BatteryStatus

func BatteryStatus() (*BatteryStatusResponse, error)

BatteryStatus acquires the corrent audio info

type CallLogPiece

type CallLogPiece struct {
	Name     string `json:"name"`
	Number   string `json:"phone_number"`
	Type     string `json:"type"`
	Date     string `json:"date"`
	Duration string `json:"duration"`
}

CallLogPiece represents one piece of call log

func CallLog

func CallLog(limit int, offset int) ([]CallLogPiece, error)

CallLog acquires call logs with a given limit and offset

type CameraInfoPiece

type CameraInfoPiece struct {
	ID              string `json:"id"`
	Facing          string `json:"facing"`
	JPEGOutputSizes []struct {
		Width  int `json:"width"`
		Height int `json:"height"`
	} `json:"jpeg_output_sizes"`
	FocalLengths []float64 `json:"focal_lengths"`
	AEModes      []string  `json:"auto_exposure_modes"`
	PhysicalSize struct {
		Width  float64 `json:"width"`
		Height float64 `json:"height"`
	} `json:"physical_size"`
	Capabilities []string `json:"capabilities"`
}

CameraInfoPiece represent the info of one camera on the device

func CameraInfo

func CameraInfo() ([]CameraInfoPiece, error)

CameraInfo gets the information of available cameras on the device

type ContactPiece

type ContactPiece struct {
	Name   string `json:"name"`
	Number string `json:"number"`
}

ContactPiece represents one contact info

func ContactList

func ContactList() ([]ContactPiece, error)

ContactList gets all contact from the device

type LocationProvider

type LocationProvider string

LocationProvider enumerates the location sources provided by the device

const (
	// GPS acquire location with GPS
	GPS LocationProvider = "gps"
	// Network acquire location using current network
	Network LocationProvider = "network"
	// Passive acquire location using passive methods
	Passive LocationProvider = "passive"
)

type LocationRecord

type LocationRecord struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
	Altitude  float64 `json:"altitude"`
	Accuracy  float64 `json:"accuracy"`
	Bearing   float64 `json:"bearing"`
	Speed     float64 `json:"speed"`
	ElapsedMS int     `json:"elapsedMs"`
	Provider  string  `json:"provider"`
}

LocationRecord represents a location record provided by the device

func LastLocation

func LastLocation(ctx context.Context, provider LocationProvider) (*LocationRecord, error)

LastLocation acquires the last known location of the device

func Location

func Location(ctx context.Context, provider LocationProvider) (*LocationRecord, error)

Location acquires the current location of the device

type NotificationButton

type NotificationButton struct {
	Text   string
	Action string
}

NotificationButton represents a button shown in the notification bar

type NotificationOpt

type NotificationOpt struct {
	Content  string
	Sound    bool
	Title    string
	Viberate []int32
	Priority NotificationPriority
	LED      struct {
		Color string
		On    int
		Off   int
	}
	Action       string
	DeleteAction string
	Btn1         NotificationButton
	Btn2         NotificationButton
	Btn3         NotificationButton
}

NotificationOpt represents the options of a notification

type NotificationPriority

type NotificationPriority string

NotificationPriority enumerates the priority level of the notification

const (
	// Max notification priority
	Max NotificationPriority = "max"
	// High notification priority
	High NotificationPriority = "high"
	// Default notification priority
	Default NotificationPriority = "default"
	// Low notification priority
	Low NotificationPriority = "low"
	// Min notification priority
	Min NotificationPriority = "min"
)

type SMS

type SMS struct {
	ThreadID int    `json:"threadid"`
	Type     string `json:"type"`
	Read     bool   `json:"read"`
	Sender   string `json:"sender"`
	Number   string `json:"number"`
	Received string `json:"received"`
	Body     string `json:"body"`
}

SMS represents a piece of received SMS

func SMSList

func SMSList(limit int, offset int, box SMSBoxType) ([]SMS, error)

SMSList acquires a list of the received SMS in the given SMS box with a given limit and offset

type SMSBoxType

type SMSBoxType int

SMSBoxType enumberates available sms box types

const (
	// All sms box type
	All SMSBoxType = 0
	// Inbox sms box type
	Inbox SMSBoxType = 1
	// Sent sms box type
	Sent SMSBoxType = 2
	// Draft sms box type
	Draft SMSBoxType = 3
	// Outbox sms box type
	Outbox SMSBoxType = 4
)

type SensorWatchOpt

type SensorWatchOpt struct {
	Limit      int
	DelayMS    int
	SensorList []string
}

SensorWatchOpt represents the options to a Sensor call

type ShareType

type ShareType = string

ShareType represent the action of the share, defaults to edit

const (
	// View share type
	View ShareType = "view"
	// Edit share type
	Edit ShareType = "edit"
	// Send share type
	Send ShareType = "send"
)

type ToastOption

type ToastOption struct {
	BGColor   string
	FontColor string
	Position  ToastPosition
	Short     bool
}

ToastOption represents the optional options to a toast

type ToastPosition

type ToastPosition string

ToastPosition enumerates current position of the toast

const (
	// Top lifts the toast ot the top of the screen
	Top ToastPosition = "top"
	// Middle is the default position of the toast
	Middle ToastPosition = "middle"
	// Bottom puts the toast to the bottom of the screen
	Bottom ToastPosition = "bottom"
)

type WifiAP

type WifiAP struct {
	BSSID     string `json:"bssid"`
	FreqMHZ   int    `json:"frequency_mhz"`
	RSSI      int    `json:"rssi"`
	SSID      string `json:"ssid"`
	TimeStamp int64  `json:"timestamp"`
	// CenterFreqMHZ not used for 20Mhz bands
	CenterFreqMHZ    int    `json:"center_frequency_mhz"`
	ChannelBandwidth string `json:"channel_bandwidth_mhz"`
}

WifiAP represents a discovered AP in a wifi scan

func WifiScan

func WifiScan() ([]WifiAP, error)

WifiScan scans for available networks

type WifiConnection

type WifiConnection struct {
	BSSID           string `json:"bssid"`
	FreqMHZ         int    `json:"frequency_mhz"`
	IP              string `json:"ip"`
	LinkSpeedMbps   int    `json:"link_speed_mbps"`
	MACAddr         string `json:"mac_address"`
	NetworkID       int    `json:"network_id"`
	RSSI            int    `json:"rssi"`
	SSID            string `json:"ssid"`
	SSIDHidden      bool   `json:"ssid_hidden"`
	SupplicantState string `json:"supplicant_state"`
}

WifiConnection represents the current connection info of the device wifi interface

func WifiConnectionState

func WifiConnectionState() (*WifiConnection, error)

WifiConnectionState returns the current wifi connection state of the device

Directories

Path Synopsis
internal
api
io

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL