This repository has been archived by the owner on Aug 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
1 deletion.
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,4 +1,20 @@ | ||
Phonegap-BackHome-Plugin | ||
======================== | ||
|
||
A cordova/phonegap plugin to send your app to background by starting Home activity | ||
## What's this? | ||
|
||
It's a cordova/phonegap plugin to send your app to background by starting Home activity. Tested on `cordova` 4.1.2 . | ||
|
||
## Installation | ||
|
||
cordova plugin add https://github.com/darkgeek/Phonegap-BackHome-Plugin.git | ||
|
||
## Usage | ||
|
||
This plugin provides one method called `goHome(successCallback, errorCallback)` to start Home activity. | ||
|
||
window.BackHome.goHome(successCallback, errorCallback); | ||
|
||
## History | ||
|
||
Originally developed by [Dpa99c](http://stackoverflow.com/users/777265/dpa99c) in [stackoverflow](http://stackoverflow.com/questions/17826122/send-application-to-background-mode-when-back-button-is-pressed-in-phonegap/17828434#17828434), and updated by me to make it work with `cordova` 4.0 and later. |
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,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<plugin id="edu.hdu.darkgeek.cordova.backhome" version="0.0.1" | ||
xmlns="http://apache.org/cordova/ns/plugins/1.0" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<name>BackHome</name> | ||
<description>Start the home activity to send your app to background</description> | ||
<js-module name="BackHome" src="www/BackHome.js"> | ||
<clobbers target="cordova.plugins.BackHome"/> | ||
</js-module> | ||
<platform name="android"> | ||
<config-file parent="/*" target="res/xml/config.xml"> | ||
<feature name="BackHome"> | ||
<param name="android-package" value="edu.hdu.darkgeek.cordova.backhome.BackHome"/> | ||
</feature> | ||
</config-file> | ||
<source-file src="src/android/BackHome.java" target-dir="src/edu/hdu/darkgeek/cordova/backhome/"/> | ||
</platform> | ||
</plugin> |
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,41 @@ | ||
package edu.hdu.darkgeek.cordova.backhome; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
|
||
import android.content.Intent; | ||
import android.util.Log; | ||
|
||
import org.apache.cordova.CallbackContext; | ||
import org.apache.cordova.CordovaPlugin; | ||
|
||
/** | ||
* A phonegap plugin to send your app to background by starting home activity. | ||
* Adapted from http://stackoverflow.com/questions/17826122/send-application-to-background-mode-when-back-button-is-pressed-in-phonegap | ||
* | ||
* @Author http://stackoverflow.com/users/777265/dpa99c (Original version, Thanks!) | ||
* @Author https://github.com/darkgeek (This version, with a bit tweeks for cordova 4.1.2) | ||
*/ | ||
public class BackHome extends CordovaPlugin { | ||
|
||
private static final String LOG_TAG = "BackHomePlugin"; | ||
|
||
@Override | ||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { | ||
if ("goHome".equals(action)) { | ||
try { | ||
Intent i = new Intent(Intent.ACTION_MAIN); | ||
i.addCategory(Intent.CATEGORY_HOME); | ||
this.cordova.getActivity().startActivity(i); | ||
|
||
} catch (Exception e) { | ||
Log.e(LOG_TAG, "Exception occurred: ".concat(e.getMessage())); | ||
return false; | ||
} | ||
callbackContext.success(); | ||
return true; | ||
} | ||
Log.e(LOG_TAG, "Called invalid action: "+action); | ||
return false; | ||
} | ||
} |
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,7 @@ | ||
window.BackHome = { | ||
goHome: function(success, error) { | ||
cordova.exec(success, error, "BackHome", "goHome", []); | ||
}, | ||
} | ||
|
||
module.exports = BackHome; |