Intent System¶
Android Intents are used to start activities, send broadcasts, and communicate between apps. QSL4A provides full Intent support through the Intent module.
Module Import¶
Intent Constants¶
Access via droid.Intent:
Actions¶
| Constant | Value | Usage |
|---|---|---|
ACTION_MAIN |
android.intent.action.MAIN | App entry point |
ACTION_VIEW |
android.intent.action.VIEW | View content |
ACTION_EDIT |
android.intent.action.EDIT | Edit content |
ACTION_PICK |
android.intent.action.PICK | Pick item |
ACTION_SEND |
android.intent.action.SEND | Share content |
ACTION_SEARCH |
android.intent.action.SEARCH | Search |
Flags¶
| Constant | Value | Usage |
|---|---|---|
FLAG_ACTIVITY_NEW_TASK |
268435456 | Start new task |
FLAG_ACTIVITY_CLEAR_TASK |
32768 | Clear task stack |
FLAG_ACTIVITY_NEW_DOCUMENT |
524288 | New document mode |
Extras¶
| Constant | Usage |
|---|---|
EXTRA_TEXT |
Text content |
EXTRA_STREAM |
File URI |
EXTRA_SUBJECT |
Subject line |
EXTRA_EMAIL |
Email address |
Core Methods¶
makeIntent()¶
Create an Intent object.
makeIntent(action, uri=None, type=None, extras=None, categories=None,
packagename=None, classname=None, flags=None)
Parameters:
- action (str): Intent action (e.g., droid.Intent.ACTION_VIEW)
- uri (str, optional): Data URI
- type (str, optional): MIME type
- extras (dict, optional): Extra data
- categories (list, optional): Intent categories
- packagename (str, optional): Target package
- classname (str, optional): Target class
- flags (int, optional): Intent flags
Returns: Intent object
startActivityIntent()¶
Start an Activity with an Intent.
Parameters:
- intent: Intent object from makeIntent()
- wait (bool, optional): Block until activity closes
startActivityForResultIntent()¶
Start activity and wait for result.
Returns: Activity result
sendBroadcastIntent()¶
Send a broadcast.
view()¶
View content by URI.
pick()¶
Pick content from URI.
Common Intent Methods)¶
scanBarcode()¶
Launch the barcode scanner.
Returns: Scanned barcode string
send()¶
Send content via share intent.
Parameters:
- type (str): MIME type
- content (str): Content to share
sendText()¶
Send text content.
Parameters:
- text (str): Text to send
sendEmail()¶
Send an email.
Parameters:
- to (str or list): Recipient email address(es)
- subject (str): Email subject
- body (str): Email body
- attachment (str, optional): Attachment file path
pathToUri()¶
Convert file path to content URI.
Parameters:
- path (str): File path
Returns: Content URI string
openFile()¶
Open a file with appropriate app.
Parameters:
- path (str): File path to open
sendFile()¶
Send a file via share intent.
Parameters:
- path (str): File path to send
getPathType()¶
Get the MIME type for a file path.
Parameters:
- path (str): File path
Returns: MIME type string
viewMap()¶
Open map at a location.
Parameters:
- latitude (float): Latitude
- longitude (float): Longitude
viewContacts()¶
Open the contacts app.
search()¶
Perform a web search.
Parameters:
- query (str): Search query
viewHtml()¶
View HTML content.
Parameters:
- content (str): HTML content
- encoding (str, optional): Character encoding
webViewShow()¶
Display web content in WebView. Deprecated, use viewHtml.
Parameters:
- url (str): Web page URL
editorOpen()¶
Open a text editor.
Parameters:
- path (str, optional): File path to edit
- create (bool, optional): Create if doesn't exist
Helper Class: Uri¶
Create URI objects for Intents:
Usage Examples¶
Open Web Page¶
intent = droid.makeIntent(
action=droid.Intent.ACTION_VIEW,
uri="http://www.example.com"
).result
droid.startActivityIntent(intent)
Share Text¶
intent = droid.makeIntent(
action=droid.Intent.ACTION_SEND,
extras={
droid.Intent.EXTRA_TEXT: "Hello from QPython!",
droid.Intent.EXTRA_SUBJECT: "Test"
},
type="text/plain"
).result
droid.startActivityIntent(intent)
Open File¶
intent = droid.makeIntent(
action=droid.Intent.ACTION_VIEW,
uri="file:///sdcard/document.pdf",
type="application/pdf"
).result
droid.startActivityIntent(intent)
Pick Contact¶
Send Email¶
intent = droid.makeIntent(
action=droid.Intent.ACTION_SEND,
extras={
droid.Intent.EXTRA_EMAIL: ["test@example.com"],
droid.Intent.EXTRA_SUBJECT: "Hello",
droid.Intent.EXTRA_TEXT: "Message body"
},
type="message/rfc822"
).result
droid.startActivityIntent(intent)