Socket
Socket
Sign inDemoInstall

capacitor-android-shortcuts

Package Overview
Dependencies
2
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    capacitor-android-shortcuts

Add shortcuts in Android


Version published
Weekly downloads
151
increased by11.03%
Maintainers
1
Install size
35.9 kB
Created
Weekly downloads
 

Readme

Source

npm version capacitor support

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

PlatformSupported
Android
iOS
Web

Install

npm install capacitor-android-shortcuts
npx cap sync android

Usage

import { AndroidShortcuts } from 'capacitor-android-shortcuts';

...

// Add dynamic shortcuts
AndroidShortcuts.isDynamicSupported().then(({ result }) => {
    if (result) {
        AndroidShortcuts.addDynamic({
            items: [
                {
                    id: "myfirstid",
                    shortLabel: "My first short label",
                    longLabel: "My first long label",
                    icon: {
                        type: "Bitmap",
                        name: "<base64-string>"
                    },
                    data: "I am a simple string",
                },
                {
                    id: "mysecondid",
                    shortLabel: "My first short label",
                    longLabel: "My first long label",
                    icon: {
                        type: "Resource",
                        name: "<vector-asset-name>"
                    },
                    data: JSON.stringify({
                        myProperty: "Pass a stringified JSON object",
                    }),
                },
            ],
        });
    }
});
...

// Add pinned shortcuts
AndroidShortcuts.isPinnedSupported().then(({ result }) => {
    if (result) {
        AndroidShortcuts.addPinned({
            id: "mypinnedid",
            shortLabel: "My pinned short label",
            longLabel: "My pinned long label",
            icon: {
                type: "Bitmap",
                name: "<base64-string>"
            },
            data: "I am a simple string",
        });
    }
});

// Triggered when app is launched by a shortcut
AndroidShortcuts.addListener('shortcut', (response: any) => {
  // response.data contains the content of the 'data' property of the created shortcut
});

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: ShortcutItem[]; }) => any

Created dynamic shortcuts

ParamTypeDescription
options{ items: {}; }An items array with the options of each shortcut

Returns: any


addPinned(...)

addPinned(options: ShortcutItem) => any

Created a pinned shortcut

ParamTypeDescription
options{ id: string; shortLabel: string; longLabel: string; icon?: { type: AvailableIconTypes; name: 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

ParamType
eventName"shortcut"
listenerFunc(response: { data: string; }) => void

Returns: any


Interfaces

PluginListenerHandle
PropType
remove() => any

Keywords

FAQs

Last updated on 14 Apr 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc