cordova-plugin-app-launcher
Simple Cordova plugin to see if other apps are installed and launch them.
0. Index
1. Description
This plugin allows you to check if an app is installed that can handle a specific uri and launch an app via uri on iOS and Android. Additionally, you may open an Android app using its package id.
- (iOS, Android) Check if any apps are installed that can launch via a specified uri.
- (iOS, Android) Launch an app via a specified uri.
- (Android) Check if an app is installed via its package id.
- (Android) Check if an app is installed for an action name.
- (Android) Launch an app via its package id.
- (Android) Launch an app for an action name.
- (Android) Launch an app with extras included.
- (Android) Return results from a launched app once it is finished.
2. Installation
Automatically (CLI / Plugman)
$ cordova plugin add https://github.com/nchutchind/cordova-plugin-app-launcher.git
and then (this step will modify your project):
$ cordova prepare
1. Add the following xml to your config.xml
:
<!-- for iOS --> <!-- Additionally, for iOS 9+, you may need to install the cordova-plugin-queries-schemes plugin, which will allow whitelisting of what URLs your app will be allowed to launch. cordova plugin add cordova-plugin-queries-schemes-->
<!-- for Android -->
2. Add www/Launcher.js
to your project and reference it in index.html
:
3. Copy the files in src/
for iOS and/or Android into your project.
iOS: Copy Launcher.h
and Launcher.m
to platforms/ios/<ProjectName>/Plugins
Android: Copy Launcher.java
to platforms/android/src/com/hutchind/cordova/plugins
(you will probably need to create this path)
PhoneGap Build (possibly outdated)
Add the following xml to your config.xml
to always use the latest version of this plugin:
or to use a specific version:
For iOS 9+, the following may need to be added so that the URLs used to launch apps can be whitelisted (in this example, customSchemeName:// and fb:// would have been the URLs registered to the apps we want to be able to launch):
customSchemeName fb
3. Usage
// Default handlers var { ; // if calling canLaunch() with getAppList:true, data will contain an array named "appList" with the package names of applications that can handle the uri specified. }; var { ; }
Check to see if Facebook can be launched via uri (iOS and Android)
windowpluginslauncher;
Check to see if Facebook is installed (Android)
windowpluginslauncher;
Launch Facebook to the logged in user's profile (iOS and Android)
windowpluginslauncher;
Launch Facebook via package id (Android)
windowpluginslauncher;
Check to see if an app is installed that can play NASA TV (Android)
windowpluginslauncher;
Get a list of installed app packages that can play NASA TV (Android)
windowpluginslauncher;
Launch NASA TV video stream in MxPlayer Free (Android)
windowpluginslauncher;
Launch MxPlayer Free with Extras for specific videos from the sdcard, specific titles, and starting at 3 seconds in (Android)
var sdcard = "file:///sdcard/"; var file1 = sdcard + "video1.mp4" file2 = sdcard + "video2.mp4"; windowpluginslauncher;
Launch MxPlayer Free with Extras for a specific video with title and return results (Android)
var filename = "file:///sdcard/video.mp4"; windowpluginslauncher;
Check to see if Peek Acuity can be launched via an Action Name (Android)
AndroidManifest.xml:
Typescript:
; window.launcher.canLaunch, console.log"Peek Acuity can be launched", console.log"Peek Acuity not installed! " + errMsg ;
Launch Peek Acuity via an Action Name with Extras and return results (Android)
; ; window.launcher.launch, , console.log"Peek Acuity error launching: " + errMsg ;
Extras Data Types
Most datatypes that can be put into an Android Bundle are able to be passed in. You must provide the datatype to convert to. Only Uri Parcelables are supported currently.
extras: "name":"myByte" "value":1 "dataType":"Byte" "name":"myByteArray" "value":1023 "dataType":"ByteArray" "name":"myShort" "value":5 "dataType":"Short" "name":"myShortArray" "value":1234 "dataType":"ShortArray" "name":"myInt" "value":2000 "dataType":"Int" "name":"myIntArray" "value":123456 "dataType":"IntArray" "name":"myIntArrayList" "value":123456789 "dataType":"IntArrayList" "name":"myLong" "value":123456789101112 "dataType":"Long" "name":"myLongArray" "value":123456789101112121110987654321 "dataType":"LongArray" "name":"myFloat" "value":1234 "dataType":"Float" "name":"myFloatArray" "value":12345678 "dataType":"FloatArray" "name":"myDouble" "value":123456789 "dataType":"Double" "name":"myDoubleArray" "value":123456789 987654321 "dataType":"DoubleArray" "name":"myBoolean" "value":false "dataType":"Boolean" "name":"myBooleanArray" "value":truefalsetrue "dataType":"BooleanArray" "name":"myString" "value":"this is a test" "dataType":"String" "name":"myStringArray" "value":"this""is" "a" "test" "dataType":"StringArray" "name":"myStringArrayList" "value":"this""is""a""test" "dataType":"StringArrayList" "name":"myChar" "value":"T" "dataType":"Char" "name":"myCharArray" "value":"this is a test" "dataType":"CharArray" "name":"myCharSequence" "value":"this is a test" "dataType":"CharSequence" "name":"myCharSequenceArray" "value":"this""is a" "test" "dataType":"CharSequenceArray" "name":"myCharSequenceArrayList" "value":"this""is a" "test" "dataType":"CharSequenceArrayList" "name":"myParcelable" "value":"http://foo" "dataType":"Parcelable" "paType":"Uri" "name":"myParcelableArray" "value":"http://foo""http://bar" "dataType":"ParcelableArray" "paType":"Uri" "name":"myParcelableArrayList" "value":"http://foo""http://bar" "dataType":"ParcelableArrayList" "paType":"Uri" "name":"mySparseParcelableArray" "value":"10":"http://foo" "-25":"http://bar" "dataType":"SparseParcelableArray" "paType":"Uri"
Launcher.canLaunch Success Callback
No data is passed.
Launcher.canLaunch Error Callback
Passes a string containing an error message.
Launcher.launch Success Callback Data
Passes a JSON object with varying parts.
Activity launched
isLaunched: true
Activity finished
isActivityDone: true
Activity launched and data returned
isActivityDone: true data: <Uri returned from Activity if any> extras <JSON object containing data returned from Activity if any>
Launcher.launch Error Callback Data
Passes an error message as a string.
4. Changelog
0.4.0: Android: Added ability to launch with intent. Thanks to [@mmey3k] for the code.
0.2.0: Android: Added ability to launch activity with extras and receive data back from launched app when it is finished.
0.1.2: Added ability to check if any apps are installed that can handle a certain datatype on Android.
0.1.1: Added ability to launch a package with a data uri and datatype on Android.
0.1.0: initial version supporting Android and iOS
5. Credits
Special thanks to @michael1t for sponsoring the development of the Extras portion of this plugin.
6. License
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.