Allow app to move to background (Android)

This commit is contained in:
Sebastián Katzer 2017-01-03 21:45:58 +01:00
parent af5da60143
commit d012080d2b
2 changed files with 26 additions and 0 deletions

View File

@ -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.
*

View File

@ -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.
*