capacitor-android-shortcuts
This plugin provides the feature to add dynamic and pinned shortcuts in Android apps. See more in the Android docs. Its possible to listen to a shortcut tap action with an event listener (see Usage
).
Dynamic shortcut
Tap and hold on the app icon and you will see the dynamic shortcuts in the dropdown
=> Usage: Call the addDynamic
method one time to add the array of dynamic shortcuts
Pinned shortcut
You can add a pinned shortcut programmatically inside your app, i.e. let a customer add a favorite of an article/product/... to the home screen
=> Usage: Call the addPinned
method where the user wants to pin something. An alert will be shown to add the pinned shortcut to the home screen.
Supported platforms
Platform | Supported |
---|
Android | ✔ |
iOS | ✖ |
Web | ✖ |
Install
npm install capacitor-android-shortcuts
npx cap sync android
Usage
import { AndroidShortcuts } from 'capacitor-android-shortcuts';
...
AndroidShortcuts.isDynamicSupported().then(({ result }) => {
if (result) {
AndroidShortcuts.addDynamic({
items: [
{
id: "myfirstid",
shortLabel: "My first short label",
longLabel: "My first long label",
iconBitmap: "BASE64DATA",
data: "I am a simple string",
},
{
id: "mysecondid",
shortLabel: "My first short label",
longLabel: "My first long label",
iconBitmap: "BASE64DATA",
data: JSON.stringify({
myProperty: "Pass a stringified JSON object",
}),
},
],
});
}
});
...
AndroidShortcuts.isPinnedSupported().then(({ result }) => {
if (result) {
AndroidShortcuts.addPinned({
id: "mypinnedid",
shortLabel: "My pinned short label",
longLabel: "My pinned long label",
iconBitmap: "BASE64DATA",
data: "I am a simple string",
});
}
});
AndroidShortcuts.addListener('shortcut', (response: any) => {
});
See also Wiki: Icon examples
API
isDynamicSupported()
isDynamicSupported() => any
Checks if dynamic shortcuts are supported on the device
Returns: any
isPinnedSupported()
isPinnedSupported() => any
Checks if pinned shortcuts are supported on the device
Returns: any
addDynamic(...)
addDynamic(options: { items: { id: string; shortLabel: string; longLabel: string; iconBitmap: string; data: string; }[]; }) => any
Created dynamic shortcuts
Param | Type | Description |
---|
options | { items: {}; } | An items array with the options of each shortcut |
Returns: any
addPinned(...)
addPinned(options: { id: string; shortLabel: string; longLabel: string; iconBitmap: string; data: string; }) => any
Created a pinned shortcut
Param | Type | Description |
---|
options | { id: string; shortLabel: string; longLabel: string; iconBitmap: string; data: string; } | An option object for the pinned shortcut |
Returns: any
addListener(...)
addListener(eventName: 'shortcut', listenerFunc: MessageListener) => Promise<PluginListenerHandle> & PluginListenerHandle
Add a listener to a shortcut tap event
Param | Type |
---|
eventName | "shortcut" |
listenerFunc | (response: any) => void |
Returns: any
Interfaces
PluginListenerHandle