You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/apps/creating-apps.md
+55Lines changed: 55 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,6 +95,61 @@ Each service entry has:
95
95
96
96
Services that subscribe to `"boot_completed"` are started automatically during system boot, after the launcher is displayed. See the [Service documentation](../frameworks/service.md) for details on writing and using services.
97
97
98
+
## Handling the view action
99
+
100
+
Apps can register themselves as file viewers by declaring an `intent_filter` with `action: "view"` and a `pathPattern` list in `MANIFEST.JSON`. This lets other apps (and the built-in `FileExplorerActivity`) open files with your app.
`pathPattern` entries are matched case-insensitively against the file extension. A leading `*` is optional. `mimeType` is recorded for documentation but is not used for matching.
123
+
124
+
### Receiving the file
125
+
126
+
When the system opens your activity via the `view` action, the file path is available in `intent.data` and also in the `filename` extra:
See [FileExplorerActivity](../frameworks/file-explorer-activity.md) for details.
216
+
217
+
### Focus Borders
218
+
Provides a single helper, `add_focus_border`, for drawing a focus border around any widget. It replaces the duplicated `FOCUSED`/`DEFOCUSED` handlers that used to exist in many apps.
219
+
220
+
```python
221
+
from mpos import add_focus_border
222
+
223
+
add_focus_border(button, width=2)
224
+
```
225
+
226
+
See [Focus Borders](../frameworks/focus.md) for details.
A common implicit intent is the `view` action, which asks the system to open a file with the most appropriate app. Apps declare which file types they can open by adding an `intent_filter` with `action: "view"` and a `pathPattern` list to their manifest. `pathPattern` entries are matched case-insensitively against the file extension; a leading `*` is optional.
1.`AppManager.resolve_activity()` looks for installed apps whose manifest `pathPattern` matches the file path.
132
+
2. If one or more specific handlers match, those handlers are returned.
133
+
3. If multiple handlers match, `ChooserActivity` shows an "Open with" dialog.
134
+
4. If no specific handler matches, the system falls back to generic handlers registered for `view`, such as the framework's built-in `ViewActivity`.
135
+
136
+
The framework `ViewActivity` provides a last-resort preview for unknown files by reading and displaying the first 512 bytes as text.
137
+
83
138
## Intent Class Reference
84
139
85
140
### Constructor
@@ -342,13 +397,24 @@ class HomeActivity(Activity):
342
397
343
398
## AppManager Intent Resolution
344
399
345
-
The `AppManager` maintains a registry of activities and their associated actions, enabling implicit intent resolution.
400
+
The `AppManager` maintains a registry of activities and their associated actions, enabling implicit intent resolution. Resolution works for both programmatically registered handlers and handlers declared in app manifests.
Apps declare file-type handlers in `MANIFEST.JSON`. When an implicit intent carries a string `data` payload (usually a file path), MicroPythonOS preferentially returns handlers whose `pathPattern` matches the path.
@@ -548,7 +637,37 @@ class HomeActivity(Activity):
548
637
549
638
---
550
639
551
-
### Pattern 5: Method Chaining
640
+
### Pattern 5: Open a File with the View Action
641
+
642
+
Use the `view` action to open a file in the app that is registered for its type. If more than one app can handle the type, the system shows an "Open with" chooser.
**Manifest registration** is preferred for file-type handlers. Add the `intent_filters` to `MANIFEST.JSON` so `AppManager.refresh_apps()` discovers the handler automatically:
929
+
930
+
```json
931
+
{
932
+
"activities": [
933
+
{
934
+
"entrypoint": "player.py",
935
+
"classname": "Player",
936
+
"intent_filters": [
937
+
{ "action": "view", "pathPattern": [".wav"] }
938
+
]
939
+
}
940
+
]
941
+
}
806
942
```
807
943
808
944
---
@@ -852,9 +988,9 @@ MicroPythonOS Intents are inspired by Android's Intent system but simplified for
0 commit comments