-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rakesh-walisheter/master
Added support for exiting app in Android
- Loading branch information
Showing
4 changed files
with
87 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |