├── src └── android │ ├── MyPackageReplacedEventReceiver.java │ ├── KioskActivity.java │ └── Kiosk.java ├── package.json ├── www └── kiosk.js ├── README.md └── plugin.xml /src/android/MyPackageReplacedEventReceiver.java: -------------------------------------------------------------------------------- 1 | package org.cordova.plugin.labs.kiosk; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | /** 8 | * Starts {@link HomeActivity} after the app APK is updated. 9 | */ 10 | public class MyPackageReplacedEventReceiver extends BroadcastReceiver { 11 | @Override 12 | public void onReceive(Context context, Intent intent) { 13 | System.out.println("Kiosk application restarting after upgrade"); 14 | Intent newIntent = new Intent(context, KioskActivity.class); 15 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 16 | context.startActivity(newIntent); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cordova-plugin-kiosk-launcher", 3 | "version": "1.1.1", 4 | "description": "Cordova plugin to make a Cordova application a launcher", 5 | "cordova": { 6 | "id": "cordova-plugin-kiosk-launcher", 7 | "platforms": [ 8 | "android" 9 | ] 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/guatedude2/cordova-plugin-kiosk-launcher.git" 14 | }, 15 | "keywords": [ 16 | "cordova", 17 | "android", 18 | "kiosk", 19 | "launcher", 20 | "ecosystem:cordova", 21 | "cordova-android" 22 | ], 23 | "author": "Apache Software Foundation", 24 | "license": "Apache 2.0", 25 | "bugs": { 26 | "url": "https://github.com/guatedude2/cordova-plugin-kiosk-launcher/issues" 27 | }, 28 | "homepage": "https://github.com/guatedude2/cordova-plugin-kiosk-launcher#readme" 29 | } 30 | -------------------------------------------------------------------------------- /www/kiosk.js: -------------------------------------------------------------------------------- 1 | var exec = require("cordova/exec"); 2 | 3 | var Kiosk = { 4 | setKioskEnabled(enabled) { 5 | exec(null, null, "Kiosk", "setKioskEnabled", [!!enabled]); 6 | }, 7 | 8 | switchLauncher: function() { 9 | exec(null, null, "Kiosk", "switchLauncher", []); 10 | }, 11 | 12 | isInKiosk: function(callback) { 13 | exec( 14 | function(out) { 15 | callback(out == "true"); 16 | }, 17 | function(error) { 18 | alert("Kiosk.isInKiosk failed: " + error); 19 | }, 20 | "Kiosk", 21 | "isInKiosk", 22 | [] 23 | ); 24 | }, 25 | 26 | isSetAsLauncher: function(callback) { 27 | exec( 28 | function(out) { 29 | callback(out == "true"); 30 | }, 31 | function(error) { 32 | alert("Kiosk.isSetAsLauncher failed: " + error); 33 | }, 34 | "Kiosk", 35 | "isSetAsLauncher", 36 | [] 37 | ); 38 | } 39 | }; 40 | 41 | module.exports = Kiosk; 42 | -------------------------------------------------------------------------------- /src/android/KioskActivity.java: -------------------------------------------------------------------------------- 1 | package org.cordova.plugin.labs.kiosk; 2 | 3 | import android.app.Activity; 4 | import android.app.ActivityManager; 5 | import android.content.Context; 6 | import android.os.Bundle; 7 | import org.apache.cordova.*; 8 | import android.widget.*; 9 | 10 | public class KioskActivity extends CordovaActivity { 11 | 12 | public static volatile boolean running = false; 13 | public static volatile boolean kioskModeEnabled = false; 14 | 15 | protected void onStart() { 16 | super.onStart(); 17 | System.out.println("KioskActivity started"); 18 | running = true; 19 | } 20 | 21 | protected void onStop() { 22 | super.onStop(); 23 | System.out.println("KioskActivity stopped"); 24 | running = false; 25 | } 26 | 27 | public void onCreate(Bundle savedInstanceState) { 28 | System.out.println("KioskActivity paused"); 29 | super.onCreate(savedInstanceState); 30 | super.init(); 31 | 32 | if (running) { 33 | finish(); // prevent more instances of kiosk activity 34 | } 35 | 36 | loadUrl(launchUrl); 37 | } 38 | 39 | @Override 40 | protected void onPause() { 41 | super.onPause(); 42 | 43 | if (kioskModeEnabled) { 44 | ActivityManager activityManager = (ActivityManager) getApplicationContext() 45 | .getSystemService(Context.ACTIVITY_SERVICE); 46 | 47 | activityManager.moveTaskToFront(getTaskId(), 0); 48 | } 49 | 50 | } 51 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cordova-plugin-kiosk-launcher 2 | 3 | **This plugin is up for adoption** 4 | 5 | > This plugin makes a cordova app become a launcher (homescreen). 6 | 7 | _Based of [https://github.com/hkalina/cordova-plugin-kiosk]._ 8 | 9 | Sets a Cordova application as a launcher 10 | 11 | **This plugin does not change behavior of application until it is set as launcher - home screen of the device.** 12 | 13 | Escape from app with this plugin is possible only using javascript call `Kiosk.exitKiosk()` 14 | or by uninstalling app using `adb`. (Keeping USB debug allowed recommended.) 15 | If applications starts as usual (not as launcher), no restrictions are applied. 16 | 17 | **This plugin only works on Android** 18 | 19 | 20 | This plugin has only been tested in Cordova 3.2 or greater, and its use in previous Cordova versions is not recommended (potential conflict with keyboard customization code present in the core in previous Cordova versions). 21 | 22 | - [Installation](#installation) 23 | - [Methods](#methods) 24 | - [Kiosk.setKiosEnabled](#kioskSetKioskEnabled) 25 | - [Kiosk.switchLauncher](#kioskSwitchLauncher) 26 | - [Kiosk.isInKiosk](#kioskIsInKiosk) 27 | - [Kiosk.isSetAsLauncher](#kioskIsSetAsLauncher) 28 | - [Releases](#releases) 29 | 30 | # Installation 31 | 32 | From [npm](https://www.npmjs.com/package/cordova-plugin-kiosk-launcher) (stable) 33 | 34 | `cordova plugin add cordova-plugin-kiosk-launcher` 35 | 36 | From github latest (may not be stable) 37 | 38 | `cordova plugin add https://github.com/guatedude2/cordova-plugin-kiosk-launcher` 39 | 40 | 41 | # Methods 42 | 43 | ## Kiosk.setKioskEnabled 44 | 45 | Enables/disables kiosk mode and 46 | 47 | Kiosk.setKioskEnabled(boolean); 48 | 49 | 50 | ## Kiosk.switchLauncher 51 | 52 | Disables kiosk mode and allows you set a different launcher 53 | 54 | Kiosk.switchLauncher(); 55 | 56 | 57 | ## Kiosk.isInKiosk 58 | 59 | Checks to see if the app is running in kiosk mode 60 | 61 | Kiosk.isInKiosk(function(isInKiosk){ ... }) 62 | 63 | ## Kiosk.isSetAsLauncher 64 | 65 | Checks to see if the app is set as a launcher 66 | 67 | Kiosk.isSetAsLauncher(function(isSetAsLauncher){ ... }) 68 | 69 | # Releases 70 | - 1.0.3 71 | - Removes fullscreen bug 72 | - 1.0.2 73 | - Fixes wrong filename 74 | - Fixes KisokActivity not running 75 | - 1.0.0 76 | - Initial NPM release 77 | -------------------------------------------------------------------------------- /src/android/Kiosk.java: -------------------------------------------------------------------------------- 1 | package org.cordova.plugin.labs.kiosk; 2 | 3 | import android.content.Intent; 4 | import android.content.pm.ResolveInfo; 5 | import android.os.Bundle; 6 | import org.apache.cordova.*; 7 | import android.widget.*; 8 | import org.json.JSONArray; 9 | import org.cordova.plugin.labs.kiosk.KioskActivity; 10 | 11 | public class Kiosk extends CordovaPlugin { 12 | 13 | public static final String SET_KIOSK_ENABLED = "setKioskEnabled"; 14 | public static final String SWITCH_LAUNCHER = "switchLauncher"; 15 | public static final String IS_IN_KIOSK = "isInKiosk"; 16 | public static final String IS_SET_AS_LAUNCHER = "isSetAsLauncher"; 17 | 18 | @Override 19 | public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { 20 | try { 21 | if (IS_IN_KIOSK.equals(action)) { 22 | 23 | callbackContext.success(Boolean.toString(KioskActivity.kioskModeEnabled)); 24 | return true; 25 | 26 | } else if (IS_SET_AS_LAUNCHER.equals(action)) { 27 | 28 | String myPackage = cordova.getActivity().getApplicationContext().getPackageName(); 29 | callbackContext.success(Boolean.toString(myPackage.equals(findLauncherPackageName()))); 30 | return true; 31 | } else if (SET_KIOSK_ENABLED.equals(action)) { 32 | KioskActivity.kioskModeEnabled = args.getBoolean(0); 33 | callbackContext.success(); 34 | return true; 35 | } else if (SWITCH_LAUNCHER.equals(action)) { 36 | KioskActivity.kioskModeEnabled = false; 37 | Intent intent = new Intent(Intent.ACTION_MAIN); 38 | intent.addCategory(Intent.CATEGORY_HOME); 39 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 40 | 41 | Intent chooser = Intent.createChooser(intent, "Select destination..."); 42 | if (intent.resolveActivity(cordova.getActivity().getPackageManager()) != null) { 43 | cordova.getActivity().startActivity(chooser); 44 | } 45 | 46 | callbackContext.success(); 47 | return true; 48 | } 49 | callbackContext.error("Invalid action"); 50 | return false; 51 | } catch(Exception e) { 52 | System.err.println("Exception: " + e.getMessage()); 53 | callbackContext.error(e.getMessage()); 54 | return false; 55 | } 56 | } 57 | 58 | private String findLauncherPackageName() { 59 | final Intent intent = new Intent(Intent.ACTION_MAIN); 60 | intent.addCategory(Intent.CATEGORY_HOME); 61 | final ResolveInfo res = this.cordova.getActivity().getPackageManager().resolveActivity(intent, 0); 62 | return res.activityInfo.packageName; 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | Scanner 5 | Cordova Kiosk Launcher Plugin 6 | Apache 2.0 7 | cordova,kiosk,launcher 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | --------------------------------------------------------------------------------