Giter Club home page Giter Club logo

cordova-plugin-shortcuts-android's Introduction

Android Shortcuts Plugin for Cordova

DESCRIPTION

Use this plugin to create shortcuts in Android. Use this plugin to handle Intents on your application.

For more information on Android App Shortcuts: https://developer.android.com/guide/topics/ui/shortcuts.html

For more information on Android Intents: https://developer.android.com/guide/components/intents-filters.html

The work that went into creating this plug-in was inspired by the existing plugins: cordova-plugin-shortcut and cordova-plugin-webintent2.

LICENSE

The MIT License

Copyright (c) 2013 Adobe Systems, inc.
portions Copyright (c) 2013 Jorge Cisneros [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

How to install it

cordova plugins add cordova-plugin-shortcuts-android

How to use it

Checking if Dynamic Shortcuts are supported

Dynamic shortcuts require SDK 25 or later. Use supportsDynamic to check whether the current device meets those requirements.

window.plugins.Shortcuts.supportsDynamic(function(supported) { 
	if (supported)
		window.alert('Dynamic shortcuts are supported');
	else
		window.alert('Dynamic shortcuts are NOT supported');
}, function(error) {
	window.alert('Error: ' + error);
})

Setting the application Dynamic Shortcuts

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.

var shortcut = {
	id: 'my_shortcut_1',
	shortLabel: 'Short description',
	longLabel: 'Longer string describing the shortcut',
	iconBitmap: '<Bitmap for the shortcut icon, base64 encoded>',
	iconResource: '<Resource name for icon>',
	intent: {
		action: 'android.intent.action.RUN',
		categories: [
			'android.intent.category.TEST', // Built-in Android category
			'MY_CATEGORY' // Custom categories are also supported
		],
		flags: 67108864, // FLAG_ACTIVITY_CLEAR_TOP
		data: 'myapp://path/to/launch?param=value', // Must be a well-formed URI
		extras: {
			'android.intent.extra.SUBJECT': 'Hello world!', // Built-in Android extra (string)
			'MY_BOOLEAN': true, // Custom extras are also supported (boolean, number and string only)
		}
	}
}
window.plugins.Shortcuts.setDynamic([shortcut], function() {
	window.alert('Shortcuts were applied successfully');
}, function(error) {
	window.alert('Error: ' + error);
})

Querying current Intent

Use getIntent to get the Intent that was used to launch the current instance of the Cordova activity.

window.plugins.Shortcuts.getIntent(function(intent) {
	window.alert(JSON.stringify(intent));
})

Subscribe to new Intents

Use onNewIntent to register a callback to be executed every time a new Intent is sent to your Cordova activity. Note that in some conditions this callback may not be executed.

For more information see the documentation for Activity.onNewIntent(Intent)

window.plugins.Shortcuts.onNewIntent(function(intent) {
	window.alert(JSON.stringify(intent));
})

Call with an empty callback to de-register the existing callback.

window.plugins.Shortcuts.onNewIntent(); // De-register existing callback

cordova-plugin-shortcuts-android's People

Contributors

avargaskun avatar

Watchers

 avatar  avatar

Forkers

justfork-repos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.