Skip to content

Commit 2f69dd8

Browse files
sertal70Sergio Talente
andauthored
feat(shortcuts-android): add cordova-plugin-shortcuts-android (#3609)
Co-authored-by: Sergio Talente <sergio@soundsofthings.com>
1 parent f32da73 commit 2f69dd8

File tree

1 file changed

+144
-0
lines changed
  • src/@ionic-native/plugins/shortcuts-android

1 file changed

+144
-0
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import { Injectable } from '@angular/core';
2+
import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';
3+
import { Observable } from 'rxjs';
4+
5+
export interface Intent {
6+
// Defaults to currently running activity
7+
activityClass?: string;
8+
9+
// Defaults to currently running package
10+
activityPackage?: string;
11+
12+
// Defaults to ACTION_VIEW
13+
action?: string;
14+
15+
// Defaults to FLAG_ACTIVITY_NEW_TASK + FLAG_ACTIVITY_CLEAR_TOP
16+
flags?: number;
17+
18+
categories?: string[];
19+
20+
data?: string;
21+
22+
extras?: { [key: string]: any };
23+
}
24+
25+
export interface Shortcut {
26+
id: string;
27+
shortLabel?: string;
28+
longLabel?: string;
29+
iconFromResource?: string;
30+
iconBitmap?: string;
31+
intent?: Intent;
32+
}
33+
34+
/**
35+
* @name ShortcutsAndroid
36+
* @description
37+
* Use this plugin to create shortcuts in Android. Use this plugin to handle Intents on your application.
38+
* For more information on Android App Shortcuts: https://developer.android.com/guide/topics/ui/shortcuts.html
39+
* For more information on Android Intents: https://developer.android.com/guide/components/intents-filters.html
40+
*
41+
* The work that went into creating this plug-in was inspired by the existing plugins: cordova-plugin-shortcut and cordova-plugin-webintent2.
42+
*
43+
* @usage
44+
* Please do refer to the original plugin's repo for detailed usage. The usage example here might not be sufficient.
45+
*
46+
* ```typescript
47+
* import { ShortcutsAndroid } from '@ionic-native/shortcuts-android/ngx';
48+
*
49+
*
50+
* constructor(private shortcutsAndroid: ShortcutsAndroid) { }
51+
*
52+
* ...
53+
*
54+
* this.shortcutsAndroid.supportsDynamic()
55+
* .then((supported: boolean) => console.log(`Dynamic shortcuts are ${supported ? '' : 'not'} supported`))
56+
* .catch((error: any) => console.error(error));
57+
*
58+
* ```
59+
*/
60+
@Plugin({
61+
pluginName: 'Shortcuts',
62+
plugin: 'cordova-plugin-shortcuts-android',
63+
pluginRef: 'plugins.Shortcuts',
64+
repo: 'https://github.com/avargaskun/cordova-plugin-shortcuts-android',
65+
platforms: ['Android'],
66+
})
67+
@Injectable()
68+
export class Shortcuts extends IonicNativePlugin {
69+
/**
70+
* Checking if Dynamic Shortcuts are supported
71+
*
72+
* Dynamic shortcuts require SDK 25 or later. Use supportsDynamic to check whether the current device meets those requirements.
73+
* @return {Promise<boolean>} returns a promise that resolves with a boolean that indicates if dynamic shortcuts are supported
74+
*/
75+
@Cordova()
76+
supportsDynamic(): Promise<boolean> {
77+
return;
78+
}
79+
80+
/**
81+
* Checking if Pinned Shortcuts are supported
82+
*
83+
* Pinned shortcuts require SDK 26 or later. Use supportsPinned to check whether the current device meets those requirements.
84+
* @return {Promise<boolean>} returns a promise that resolves with a boolean that indicates if pinned shortcuts are supported
85+
*/
86+
@Cordova()
87+
supportsPinned(): Promise<boolean> {
88+
return;
89+
}
90+
91+
/**
92+
* Setting the application Dynamic Shortcuts
93+
*
94+
* Use `setDynamic` to set the Dynamic Shortcuts for the application, all at once. The shortcuts provided as a parameter will override any existing shortcut. Use an empty array to clear out existing shortcuts.
95+
* @param {Shortcut[]} [shortcut] Array of shortcuts to add.
96+
* @return {Promise<void>}
97+
*/
98+
@Cordova({
99+
successIndex: 1,
100+
errorIndex: 2,
101+
})
102+
setDynamic(shortcuts: Shortcut[]): Promise<void> {
103+
return;
104+
}
105+
106+
/**
107+
* Adding a Pinned Shortcut to the launcher
108+
*
109+
* Use `addPinned` to add a new Pinned Shortcut to the launcher.
110+
* @param {Shortcut[]} [shortcut] Array of shortcuts to add.
111+
* @return {Promise<void>}
112+
*/
113+
@Cordova({
114+
successIndex: 1,
115+
errorIndex: 2,
116+
})
117+
addPinned(shortcut: Shortcut): Promise<void> {
118+
return;
119+
}
120+
121+
/**
122+
* Querying current Intent
123+
*
124+
* Use `getIntent` to get the Intent that was used to launch the current instance of the Cordova activity.
125+
* @return {Promise<Intent>} returns the Intent that was used to launch the current instance of the Cordova activity
126+
*/
127+
@Cordova()
128+
getIntent(): Promise<Intent> {
129+
return;
130+
}
131+
132+
/**
133+
* Subscribe to new Intents
134+
*
135+
* Use onNewIntent to trigger your code every time a new Intent is sent to your Cordova activity. Note that in some conditions this subscription may not be executed.
136+
* @return {Observable<Intent>} emits the new Intent each time a shortcut is activated
137+
*/
138+
@Cordova({
139+
observable: true,
140+
})
141+
onNewIntent(): Observable<Intent> {
142+
return;
143+
}
144+
}

0 commit comments

Comments
 (0)