diff --git a/src/android/BackgroundMode.java b/src/android/BackgroundMode.java index 3a7f70d..fa70495 100644 --- a/src/android/BackgroundMode.java +++ b/src/android/BackgroundMode.java @@ -109,6 +109,11 @@ public class BackgroundMode extends CordovaPlugin { return true; } + if (action.equalsIgnoreCase("background")) { + moveToBackground(); + return true; + } + if (action.equalsIgnoreCase("enable")) { enableMode(); return true; @@ -303,6 +308,16 @@ public class BackgroundMode extends CordovaPlugin { thread.start(); } + /** + * Send app to background. + */ + private void moveToBackground() { + Intent intent = new Intent(Intent.ACTION_MAIN); + + intent.addCategory(Intent.CATEGORY_HOME); + cordova.getActivity().startActivity(intent); + } + /** * Fire vent with some parameters inside the web view. * diff --git a/www/background-mode.js b/www/background-mode.js index c2cf995..81ec97e 100644 --- a/www/background-mode.js +++ b/www/background-mode.js @@ -99,6 +99,17 @@ exports.disableWebViewOptimizations = function () { } }; +/** + * Move app to background (Android only). + * + * @return [ Void ] + */ +exports.moveToBackground = function () { + if (device.platform == 'Android') { + cordova.exec(null, null, 'BackgroundMode', 'background', []); + } +}; + /** * If the mode is enabled or disabled. *