@simplymobile/capacitor-web-intent
v8.0.0
Published
Capacitor port of simply-web-intent-plugin (Android Intent shim).
Readme
@simplymobile/capacitor-web-intent
Capacitor port of simply-web-intent-plugin (Android Intent shim).
Install
npm install @simplymobile/capacitor-web-intent
npx cap syncAPI
startActivity(...)startActivityForResult(...)sendBroadcast(...)startService(...)registerBroadcastReceiver(...)unregisterBroadcastReceiver()getIntent()sendResult(...)realPathFromUri(...)packageExists(...)addListener('newIntent', ...)addListener('broadcastReceived', ...)addListener('activityResult', ...)removeAllListeners()- Interfaces
- Type Aliases
startActivity(...)
startActivity(options: IntentOptions) => Promise<void>Start an Activity using the supplied Intent.
| Param | Type |
| ------------- | ------------------------------------------------------- |
| options | IntentOptions |
startActivityForResult(...)
startActivityForResult(options: IntentOptions) => Promise<ActivityResult>Start an Activity expecting a result back. Resolves with the
ActivityResult once the started Activity returns.
| Param | Type |
| ------------- | ------------------------------------------------------- |
| options | IntentOptions |
Returns: Promise<ActivityResult>
sendBroadcast(...)
sendBroadcast(options: IntentOptions) => Promise<void>Send a broadcast Intent.
| Param | Type |
| ------------- | ------------------------------------------------------- |
| options | IntentOptions |
startService(...)
startService(options: IntentOptions) => Promise<void>Start a Service Intent.
| Param | Type |
| ------------- | ------------------------------------------------------- |
| options | IntentOptions |
registerBroadcastReceiver(...)
registerBroadcastReceiver(options: BroadcastReceiverFilter) => Promise<void>Register a BroadcastReceiver for the supplied filter. Incoming
broadcasts are delivered via the broadcastReceived listener.
| Param | Type |
| ------------- | --------------------------------------------------------------------------- |
| options | BroadcastReceiverFilter |
unregisterBroadcastReceiver()
unregisterBroadcastReceiver() => Promise<void>Unregister every receiver registered by this plugin.
getIntent()
getIntent() => Promise<IntentResult>Read the current Activity intent (or any intent deferred since the last
getIntent / newIntent listener).
Returns: Promise<IntentResult>
sendResult(...)
sendResult(options?: SendResultOptions | undefined) => Promise<void>Set the current Activity result and finish it. Useful when the app was
launched via startActivityForResult from another app.
| Param | Type |
| ------------- | --------------------------------------------------------------- |
| options | SendResultOptions |
realPathFromUri(...)
realPathFromUri(options: RealPathOptions) => Promise<RealPathResult>Resolve a content URI to a real file path (best effort, Android KitKat+).
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| options | RealPathOptions |
Returns: Promise<RealPathResult>
packageExists(...)
packageExists(options: PackageExistsOptions) => Promise<PackageExistsResult>Check whether the supplied package is installed on the device.
| Param | Type |
| ------------- | --------------------------------------------------------------------- |
| options | PackageExistsOptions |
Returns: Promise<PackageExistsResult>
addListener('newIntent', ...)
addListener(eventName: 'newIntent', listenerFunc: (intent: IntentResult) => void) => Promise<PluginListenerHandle>Listen for onNewIntent callbacks from the host Activity. Useful for
deep-links and NFC/RFID intents delivered while the app is in the
foreground.
| Param | Type |
| ------------------ | -------------------------------------------------------------------------- |
| eventName | 'newIntent' |
| listenerFunc | (intent: IntentResult) => void |
Returns: Promise<PluginListenerHandle>
addListener('broadcastReceived', ...)
addListener(eventName: 'broadcastReceived', listenerFunc: (intent: IntentResult) => void) => Promise<PluginListenerHandle>Listen for broadcasts matching any filter registered via
registerBroadcastReceiver.
| Param | Type |
| ------------------ | -------------------------------------------------------------------------- |
| eventName | 'broadcastReceived' |
| listenerFunc | (intent: IntentResult) => void |
Returns: Promise<PluginListenerHandle>
addListener('activityResult', ...)
addListener(eventName: 'activityResult', listenerFunc: (result: ActivityResult) => void) => Promise<PluginListenerHandle>Listen for activity results delivered by startActivityForResult. The
same payload is also returned by the startActivityForResult promise —
use this listener when you need to observe results across multiple
launches or after a re-bind.
| Param | Type |
| ------------------ | ------------------------------------------------------------------------------ |
| eventName | 'activityResult' |
| listenerFunc | (result: ActivityResult) => void |
Returns: Promise<PluginListenerHandle>
removeAllListeners()
removeAllListeners() => Promise<void>Remove every listener registered through this plugin.
Interfaces
IntentOptions
Options accepted by startActivity, startActivityForResult,
sendBroadcast and startService.
| Prop | Type | Description |
| ----------------- | ----------------------------------------------------------- | -------------------------------------------------------------------- |
| action | string | |
| url | string | |
| type | string | |
| package | string | |
| component | IntentComponent | |
| flags | number[] | |
| extras | IntentExtras | |
| chooser | string | Wrap the intent in Intent.createChooser(intent, chooser) when set. |
| requestCode | number | Request code used by startActivityForResult. Default: 1. |
IntentComponent
Explicit component target (package + class).
| Prop | Type |
| ------------- | ------------------- |
| package | string |
| class | string |
ActivityResult
Payload delivered by startActivityForResult and by the
activityResult event.
| Prop | Type |
| ----------------- | ------------------- |
| requestCode | number |
| resultCode | number |
BroadcastReceiverFilter
Options for registerBroadcastReceiver.
| Prop | Type |
| ----------------------- | --------------------- |
| filterActions | string[] |
| filterCategories | string[] |
| filterDataSchemes | string[] |
IntentResult
JSON representation of an Android Intent.
| Prop | Type |
| ---------------- | ------------------------------------------------------------------------ |
| action | string | null |
| type | string | null |
| data | string | null |
| categories | string[] | null |
| flags | number |
| component | string | null |
| package | string | null |
| extras | Record<string, unknown> | null |
| clipItems | IntentClipItem[] |
IntentClipItem
One item of an Intent.getClipData() payload.
| Prop | Type |
| --------------- | --------------------------- |
| htmlText | string | null |
| intent | unknown |
| text | string | null |
| uri | string | null |
| type | string | null |
| extension | string | null |
SendResultOptions
Options accepted by sendResult.
| Prop | Type |
| ------------ | ----------------------------------------------------- |
| extras | IntentExtras |
RealPathResult
| Prop | Type |
| -------------- | ------------------- |
| filePath | string |
RealPathOptions
Options accepted by realPathFromUri.
| Prop | Type |
| --------- | ------------------- |
| uri | string |
PackageExistsResult
| Prop | Type |
| ------------ | -------------------- |
| exists | boolean |
PackageExistsOptions
Options accepted by packageExists.
| Prop | Type |
| ------------- | ------------------- |
| package | string |
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
Type Aliases
IntentExtras
A bag of Intent extras. Values may be primitives, arrays of primitives, or
a nested object (mapped to a Bundle on the native side).
Record<string, unknown>
Record
Construct a type with a set of properties K of type T
{ [P in K]: T; }
