mobile

package
v1.9.9 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mobile is the logic of the desktop services of package desktop on a mobile platform (Android in 1.6, SPEC §24.11): opening a URI with an intent and showing notifications through the system's notification manager. It is plain Go over two small interfaces, IntentOpener and NotificationAPI, that the platform implements over its Java side; it has no operating-system code, so every build and the normal test run can use and test it, as with the web's internal/platform/web Desktop (SPEC §23.7). It is a package of its own, not part of internal/platform/android, so that package desktop can use its types on every target without importing an Android backend (SPEC §6.3).

Index

Constants

View Source
const DefaultAction = "default"

DefaultAction is the ID of the action that a click on the notification itself calls.

Flutter: no counterpart

View Source
const ServiceDesktop = "desktop"

ServiceDesktop is the name under which the engine hands Services to package desktop (ui.PlatformDispatcher.PlatformService).

Flutter: no counterpart

Variables

This section is empty.

Functions

func URIScheme

func URIScheme(raw string) string

URIScheme is the scheme of the URI as a browser reads it (leading control characters and spaces are dropped, tabs and newlines inside it are ignored), in lower case; it is empty when the URI has none.

Flutter: no counterpart

Types

type Action

type Action struct{ ID, Label string }

Action is a button of a notification, or, with the ID "default", the click on the notification.

Flutter: no counterpart

type Blocked

type Blocked struct{ Reason string }

Blocked is a notification that the user turned off for the app or for its channel.

Flutter: no counterpart

func (Blocked) Error

func (b Blocked) Error() string

Error implements error.

type CloseReason

type CloseReason int

CloseReason is why a notification went away. The values are those of the Desktop Notifications specification, as package desktop's NotificationCloseReason has them.

Flutter: no counterpart

const (
	// CloseUnknown is a close that the app cannot explain.
	//
	// Flutter: no counterpart
	CloseUnknown CloseReason = iota
	// CloseExpired is a notification whose Timeout was up.
	//
	// Flutter: no counterpart
	CloseExpired
	// CloseDismissed is a notification that the user swiped away, or that closed after a click.
	//
	// Flutter: no counterpart
	CloseDismissed
	// CloseByApp is a notification that the app closed.
	//
	// Flutter: no counterpart
	CloseByApp
)

The reasons a notification closes.

type Desktop

type Desktop struct {
	// contains filtered or unexported fields
}

Desktop is what package desktop calls on Android (SPEC §24.11): OpenURI, ShowNotification and CloseNotification. Its methods may be called from any goroutine but the UI's: ShowNotification waits for the permission prompt, which the UI goroutine must never do (SPEC §24.3).

Flutter: no counterpart (Flutter apps use the url_launcher and flutter_local_notifications plugins)

func NewDesktop

func NewDesktop(opener IntentOpener, notes NotificationAPI, after func(time.Duration, func()) func()) *Desktop

NewDesktop makes a Desktop over the Java side; either part may be nil, for a host that does not have it. after starts a timer (time.AfterFunc when nil); tests give their own clock.

Flutter: no counterpart

func (*Desktop) Action

func (d *Desktop) Action(serial int, actionID string)

Action is the system telling that the user chose the button with the ID of the notification with the serial: the action is called and the notification closed as dismissed. A button that the notification does not have is ignored.

Flutter: no counterpart

func (*Desktop) Clicked

func (d *Desktop) Clicked(serial int)

Clicked is the system telling that the user clicked the notification with the serial: the action "default" is called when the notification has it, and the notification is closed (Android removes a notification that was clicked), as dismissed.

Flutter: no counterpart

func (*Desktop) CloseNotification

func (d *Desktop) CloseNotification(_ context.Context, id uint32) error

CloseNotification closes the notification with the ID, which calls its OnClose with CloseByApp. Closing one that is gone is not an error; a program without an Android activity is NotificationsUnavailable.

Flutter: no counterpart

func (*Desktop) Closed

func (d *Desktop) Closed(serial int, reason CloseReason)

Closed is the system telling that the notification with the serial is gone and the Desktop did not remove it: the user swiped it away.

Flutter: no counterpart

func (*Desktop) OpenURI

func (d *Desktop) OpenURI(ctx context.Context, uri string) error

OpenURI starts an ACTION_VIEW intent for the URI (SPEC §24.11). A scheme that runs script (javascript:, vbscript:) is OpenURISchemeBlocked, as on the web. A URI that no app can handle, a program with no activity to start it from, and a refusal of the system are OpenURIUnavailable, with the reason in the metadata.

Flutter: no counterpart (url_launcher_android: launchUrl)

func (*Desktop) ShowNotification

func (d *Desktop) ShowNotification(ctx context.Context, spec NotificationSpec) (uint32, error)

ShowNotification posts the notification and returns its ID. The first call asks the user for the permission when Android 13 or later wants it; a permission that is not granted, and a user who turned the notifications off, are NotificationsUnavailable (SPEC §24.11). A spec with ReplacesID of a notification that is shown replaces it and keeps its ID. A notification manager that refuses the notification is AndroidNotificationFailed.

Flutter: no counterpart (flutter_local_notifications)

type IntentOpener

type IntentOpener interface {
	// Open starts an ACTION_VIEW intent for the URI. It fails with a Refused that says why when no app
	// can handle the URI, when the app has no activity to start it from, or when the system refuses.
	// It returns when the system has answered or ctx ends.
	Open(ctx context.Context, uri string) error
}

IntentOpener starts the activity that views a URI (ACTION_VIEW).

Flutter: no counterpart

type Notification

type Notification struct {
	// ID is the notification's ID in the notification manager; a notification with the ID of one that is
	// shown replaces it. Serial tells the notifications that had the same ID apart: the events of the
	// sink carry it.
	ID     uint32
	Serial int
	// Title and Body are plain text.
	Title, Body string
	// Urgency chooses the channel: one per urgency.
	Urgency Urgency
	// Actions are the buttons, in order; the action "default" is not among them (it is the click on the
	// notification itself).
	Actions []Action
	// Timeout, when positive, is how long the notification stays; the system removes it after that
	// (plus some grace), as a backstop for the Desktop's own timer.
	Timeout time.Duration
}

Notification is what NotificationAPI.Show posts: one notification of the notification manager.

Flutter: no counterpart

type NotificationAPI

type NotificationAPI interface {
	// SetSink says who to tell about the clicks and the closing of the notifications.
	SetSink(Sink)
	// Status reads whether the app may post now.
	Status(ctx context.Context) (Status, error)
	// RequestPermission starts the system's permission prompt and returns; done is called once, later,
	// on any goroutine, with the user's answer or the reason the request failed.
	RequestPermission(done func(Permission, error))
	// Show posts the notification. It fails with a Blocked when the notification manager takes it but
	// the user turned it off (the app's notifications, or the channel), and otherwise with a Refused.
	// It returns when the system has answered or ctx ends.
	Show(ctx context.Context, n Notification) error
	// Cancel removes the notification with the ID (NotificationManager.cancel).
	Cancel(id uint32)
}

NotificationAPI is the notification manager as the Desktop uses it. internal/platform/android is the real one, and the tests use a fake.

Flutter: no counterpart

type NotificationSpec

type NotificationSpec struct {
	// Title is the summary; Body the plain text under it.
	Title, Body string
	// Urgency chooses the channel.
	Urgency Urgency
	// Timeout, when positive, closes the notification after that long, with CloseExpired. A
	// notification that must be acted on (Persistent, Critical) has none.
	Timeout time.Duration
	// ReplacesID is the ID of a notification that is shown, which this one replaces; zero makes a new
	// one.
	ReplacesID uint32
	// Actions are the buttons; the one with the ID "default" is the click on the notification.
	Actions []Action
	// Icon is the path of an image file or the name of a theme icon, as the app gave it. Windows uses a
	// PNG or JPEG file as the large icon of the balloon; Android and the web have their own icons.
	Icon string
	// OnAction is called, on any goroutine, with the ID of the action the user chose; the click on the
	// notification is the action "default", only when Actions has it. nil listens to nothing.
	OnAction func(id string)
	// OnClose is called, on any goroutine, once, when the notification goes away. A notification that
	// another one replaced does not call it.
	OnClose func(CloseReason)
}

NotificationSpec is a notification for Desktop.ShowNotification.

Flutter: no counterpart

type Permission

type Permission int

Permission is the answer of the user to the system's permission prompt.

Flutter: no counterpart

const (
	// PermissionUndecided is a request that ended without a decision of the user (no activity to show
	// the prompt over, or the prompt was interrupted): it is not remembered.
	//
	// Flutter: no counterpart
	PermissionUndecided Permission = iota
	// PermissionGranted is the user allowing notifications.
	//
	// Flutter: no counterpart
	PermissionGranted
	// PermissionDenied is the user refusing (or the system refusing for the user, after two refusals).
	//
	// Flutter: no counterpart
	PermissionDenied
)

The answers to a request for the permission to post notifications.

type Refused

type Refused struct{ Detail string }

Refused is the reason that the Java side did not do what it was asked.

Flutter: no counterpart

func (Refused) Error

func (r Refused) Error() string

Error implements error.

type Services

type Services interface {
	// OpenURI opens the URI in the app that views it.
	OpenURI(ctx context.Context, uri string) error
	// ShowNotification shows the notification and returns its ID.
	ShowNotification(ctx context.Context, spec NotificationSpec) (uint32, error)
	// CloseNotification closes the notification with the ID.
	CloseNotification(ctx context.Context, id uint32) error
}

Services is what package desktop calls on a mobile platform. *Desktop is the implementation.

Flutter: no counterpart

type Sink

type Sink interface {
	// Clicked is the click on the notification with the serial.
	Clicked(serial int)
	// Action is the click on the button with the ID, of the notification with the serial.
	Action(serial int, id string)
	// Closed is the end of the notification with the serial, which the system did (CloseDismissed when
	// the user swiped it away) and the Desktop did not.
	Closed(serial int, reason CloseReason)
}

Sink is told about the events of the notifications that Show posted. Its methods are called on any goroutine, including a thread of the platform that must not wait.

Flutter: no counterpart

type Status

type Status struct {
	// PermissionNeeded says that the system asks the user for a permission before the app may post (the
	// runtime permission POST_NOTIFICATIONS of Android 13 and later), and PermissionGranted that the app
	// has it. Both are meaningful only together: PermissionGranted is true when none is needed.
	PermissionNeeded, PermissionGranted bool
	// Enabled is NotificationManager.areNotificationsEnabled: false when the user turned the app's
	// notifications off.
	Enabled bool
}

Status is what the notification manager says about the app.

Flutter: no counterpart

type Urgency

type Urgency int

Urgency is how important a notification is. The zero value is Normal.

Flutter: no counterpart

const (
	// UrgencyNormal is the usual one (IMPORTANCE_DEFAULT).
	//
	// Flutter: no counterpart
	UrgencyNormal Urgency = iota
	// UrgencyLow makes no sound (IMPORTANCE_LOW).
	//
	// Flutter: no counterpart
	UrgencyLow
	// UrgencyCritical shows over the screen (IMPORTANCE_HIGH).
	//
	// Flutter: no counterpart
	UrgencyCritical
)

The urgencies, one channel each.

Jump to

Keyboard shortcuts

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