session.phone reports state from the user’s phone: notifications as they post,
calendar events, and the phone’s own battery. Each concern is its own sub-module.
Register a handler and the events start arriving.
src/background/index.ts
READ_NOTIFICATIONS permission and calendar events need
the CALENDAR permission, both declared in your
manifest. Phone battery needs no
permission.
Notifications
session.phone.notifications.on() fires when a notification posts on the phone.
PhoneNotificationData:
Dismissals
session.phone.notifications.onDismissed() fires when the user swipes away or
clears a notification.
NotificationDismissedData:
onDismissed is Android only. iOS does not expose dismiss callbacks to apps
(an Apple privacy restriction), so subscribing on iOS succeeds but no events ever
fire. The matching notifications.on() post-event works on both platforms.Calendar
session.phone.calendar.listEvents() reads a current snapshot from all event
calendars on the phone. Declare CALENDAR as a required permission; the Mentra
App requests access before opening the miniapp.
limit defaults to 50 and may not
exceed 100. The result contains events and a truncated flag. Each event has:
Phone battery
session.phone.onBattery() reports the phone’s battery. It stays flat (not
sub-namespaced) because it’s a single event.
BatteryData:
Cleaning up
Every subscription returns an unsubscribe function. Thenotifications
sub-module also has a stop() that tears down every notification subscription
at once. Calendar snapshots do not create a subscription.
session.phone.notifications.hasPermission tells you whether READ_NOTIFICATIONS
is declared in your manifest, and session.phone.calendar.hasPermission tells you
whether CALENDAR is declared. Neither tells you whether the user granted the OS
prompt. A calendar request rejects with PERMISSION_DENIED if access was later
revoked. See
Permissions.
