#23 Notifications while app is suspended

This commit is contained in:
EddyVerbruggen 2015-01-13 13:48:17 +01:00
parent 2fdfde7a1a
commit 23e5029f89
3 changed files with 29 additions and 7 deletions

View File

@ -61,15 +61,17 @@ Windows Phone 8
### Automatically (CLI / Plugman) ### Automatically (CLI / Plugman)
Toast is compatible with [Cordova Plugman](https://github.com/apache/cordova-plugman), compatible with [PhoneGap 3.0 CLI](http://docs.phonegap.com/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface_add_features), here's how it works with the CLI (backup your project first!): Toast is compatible with [Cordova Plugman](https://github.com/apache/cordova-plugman), compatible with [PhoneGap 3.0 CLI](http://docs.phonegap.com/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface_add_features), here's how it works with the CLI (backup your project first!):
Using the Cordova CLI and the [Cordova Plugin Registry](http://plugins.cordova.io)
``` ```
$ phonegap local plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git $ cordova plugin add nl.x-services.plugins.toast
```
or
```
$ cordova plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
$ cordova prepare $ cordova prepare
``` ```
Or using the phonegap CLI
```
$ phonegap local plugin add nl.x-services.plugins.toast
```
Toast.js is brought in automatically. There is no need to change or add anything in your html. Toast.js is brought in automatically. There is no need to change or add anything in your html.
### Manually ### Manually

View File

@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
id="nl.x-services.plugins.toast" id="nl.x-services.plugins.toast"
version="2.0.2"> version="2.0.3">
<name>Toast</name> <name>Toast</name>
@ -11,8 +11,16 @@
A Toast is a little non intrusive buttonless popup which automatically disappears. A Toast is a little non intrusive buttonless popup which automatically disappears.
</description> </description>
<author>Eddy Verbruggen</author>
<license>MIT</license> <license>MIT</license>
<keywords>Toast, Notification, Message, Alert</keywords>
<repo>https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git</repo>
<issue>https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/issues</issue>
<engines> <engines>
<engine name="cordova" version=">=3.0.0"/> <engine name="cordova" version=">=3.0.0"/>
</engines> </engines>

View File

@ -13,11 +13,15 @@ import org.json.JSONException;
public void onTick(long millisUntilFinished) {toast.show();} public void onTick(long millisUntilFinished) {toast.show();}
public void onFinish() {toast.show();} public void onFinish() {toast.show();}
}.start(); }.start();
Also, check https://github.com/JohnPersano/SuperToasts
*/ */
public class Toast extends CordovaPlugin { public class Toast extends CordovaPlugin {
private static final String ACTION_SHOW_EVENT = "show"; private static final String ACTION_SHOW_EVENT = "show";
private android.widget.Toast mostRecentToast;
@Override @Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (ACTION_SHOW_EVENT.equals(action)) { if (ACTION_SHOW_EVENT.equals(action)) {
@ -51,6 +55,7 @@ public class Toast extends CordovaPlugin {
} }
toast.show(); toast.show();
mostRecentToast = toast;
callbackContext.success(); callbackContext.success();
} }
}); });
@ -61,4 +66,11 @@ public class Toast extends CordovaPlugin {
return false; return false;
} }
} }
}
@Override
public void onPause(boolean multitasking) {
if (mostRecentToast != null) {
mostRecentToast.cancel();
}
}
}