Skip to content

Commit

Permalink
Merge pull request #2 from rakesh-walisheter/master
Browse files Browse the repository at this point in the history
Added support for exiting app in Android
  • Loading branch information
gaqzi committed Nov 3, 2015
2 parents 545ee87 + aa3c004 commit 1286ede
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 10 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
cordova-plugin-exitapp
----------------------

This plugin adds the ability to close a Windows Phone 8 app
programatically. It was build because a WP8 app was rejected because
it didn't close the app with custom back button behavior.
This plugin adds the ability to programmatically close an app on Android or Windows Phone 8.

## Installation

Package name on the [Cordova plugin repository](http://plugins.cordova.io) is [se.sanitarium.cordova.exitapp](http://plugins.cordova.io/#/se.sanitarium.cordova.exitapp).
Plugin id: cordova.custom.plugins.exitapp

To install this plugin, follow the [Command-line Interface Guide](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface).

If you are not using the Cordova Command-line Interface, follow [Using Plugman to Manage Plugins](http://cordova.apache.org/docs/en/edge/plugin_ref_plugman.md.html).

## Usage

The usage is extremely simple:
confirmed = function(buttonIndex) {
if(buttonIndex == 1) {
console.log("navigator.app.exitApp");
navigator.app.exitApp();
}
}

```
navigator.app.exitApp();
```
onTouch = function() {
navigator.notification.confirm('', confirmed, 'Exit?');
}
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "cordova-plugin-exitapp",
"version": "1.0.0",
"description": "Implements navigator.app.exitApp on WP8, Android",
"cordova": {
"id": "cordova.custom.plugins.exitapp",
"platforms": [
"wp8",
"android"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/rakesh-walisheter/cordova-plugin-exitapp.git"
},
"keywords": [
"cordova",
"exit",
"terminate",
"ecosystem:cordova",
"cordova-wp8",
"cordova-android"
],
"author": "Rakesh Walisheter",
"license": "Apache 2.0",
"bugs": {
"url": "https://github.com/rakesh-walisheter/cordova-plugin-exitapp/issues"
},
"homepage": "https://github.com/rakesh-walisheter/cordova-plugin-exitapp#readme"
}
14 changes: 12 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="se.sanitarium.cordova.exitapp"
id="cordova.custom.plugins.exitapp"
version="1.0.0">

<name>ExitApp</name>
<description>Implements navigator.app.exitApp on WP8</description>
<description>Implements navigator.app.exitApp on WP8, Android</description>
<license>Apache 2.0</license>
<keywords>cordova,terminate</keywords>

Expand All @@ -22,4 +22,14 @@

<source-file src="src/wp/ExitApp.cs" />
</platform>

<!-- android -->
<platform name="android">
<config-file target="config.xml" parent="/*">
<feature name="ExitApp">
<param name="android-package" value="cordova.custom.plugins.exitapp.ExitApp" />
</feature>
</config-file>
<source-file src="src/android/ExitApp.java" target-dir="src/cordova/custom/plugins/exitapp" />
</platform>
</plugin>
34 changes: 34 additions & 0 deletions src/android/ExitApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cordova.custom.plugins.exitapp;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;

public class ExitApp extends CordovaPlugin {
protected void pluginInitialize() {}

public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
/*
* Finishes the activity provided by CordovaInterface.
*/

if (action.equals("exitApp")) {
try {
Activity activity = this.cordova.getActivity();
activity.finish();
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
} catch (Exception e) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, 1));
}
return true;
}
return false;
}
}

0 comments on commit 1286ede

Please sign in to comment.