The SMS plugin provides read-only access to device SMS messages across inbox, sent, and draft folders.

Setup

The SMS plugin is already registered in the default AppTemplate.

Android Manifest

<uses-permission android:name="android.permission.READ_SMS" />

Note: On Android 4.4+ (KITKAT), this plugin can only read SMS messages if your app is the default SMS app.

API

sms.GetRecent(limit int) (SmsFolder, error)

Fetches the most recent SMS messages across all folders.

Returns: SmsFolder or error

sms.GetLast(limit int) (SmsFolder, error)

An alias for GetRecent(limit).

sms.GetInbox() (SmsFolder, error)

Fetches messages from the inbox.

Returns: SmsFolder or error

sms.GetSent() (SmsFolder, error)

Fetches messages from the sent folder.

Returns: SmsFolder or error

sms.GetDrafts() (SmsFolder, error)

Fetches messages from the drafts folder.

Returns: SmsFolder or error

sms.GetAll() (SmsFolder, error)

Fetches all messages from inbox, sent, and draft folders.

Returns: SmsFolder or error

Types

SmsFolder

type SmsFolder struct {
    Messages []SmsMessage `json:"messages"`
    Count    int          `json:"count"`
    Folder   string       `json:"folder"`
}

SmsMessage

Field Type Description
ID int64 Stable row ID
Address string Sender or recipient address
Body string Message text
Type string "inbox", "sent", or "draft"
Timestamp int64 Epoch millis
Read bool Whether the message has been read

Events

sms:changed

Emitted when the native side detects an SMS change.

Example

import "github.com/sweet-juice/sweetjuice/plugins/sms"

plugin := sms.NewPlugin()
folder, err := plugin.GetAll()