mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-22 07:14:54 +00:00
Update notification when calling configure in background
This commit is contained in:
parent
8b7ef48cff
commit
3cf8b62e84
@ -21,6 +21,12 @@
|
|||||||
|
|
||||||
package de.appplant.cordova.plugin.background;
|
package de.appplant.cordova.plugin.background;
|
||||||
|
|
||||||
|
import org.apache.cordova.CallbackContext;
|
||||||
|
import org.apache.cordova.CordovaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -29,12 +35,6 @@ import android.content.ServiceConnection;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.apache.cordova.CallbackContext;
|
|
||||||
import org.apache.cordova.CordovaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
public class BackgroundMode extends CordovaPlugin {
|
public class BackgroundMode extends CordovaPlugin {
|
||||||
|
|
||||||
// Flag indicates if the app is in background or foreground
|
// Flag indicates if the app is in background or foreground
|
||||||
@ -47,7 +47,7 @@ public class BackgroundMode extends CordovaPlugin {
|
|||||||
static JSONObject settings = new JSONObject();
|
static JSONObject settings = new JSONObject();
|
||||||
|
|
||||||
// Used to (un)bind the service to with the activity
|
// Used to (un)bind the service to with the activity
|
||||||
private ServiceConnection connection = new ServiceConnection() {
|
private final ServiceConnection connection = new ServiceConnection() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder binder) {
|
public void onServiceConnected(ComponentName name, IBinder binder) {
|
||||||
@ -85,7 +85,8 @@ public class BackgroundMode extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (action.equalsIgnoreCase("configure")) {
|
if (action.equalsIgnoreCase("configure")) {
|
||||||
settings = args.getJSONObject(0);
|
setSettings(args.getJSONObject(0));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +155,20 @@ public class BackgroundMode extends CordovaPlugin {
|
|||||||
isDisabled = true;
|
isDisabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the settings and maybe the notification.
|
||||||
|
*
|
||||||
|
* @param settings
|
||||||
|
*/
|
||||||
|
private void setSettings(JSONObject settings) {
|
||||||
|
this.settings = settings;
|
||||||
|
|
||||||
|
if (inBackground) {
|
||||||
|
stopService();
|
||||||
|
startService();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bind the activity to a background service and put them into foreground
|
* Bind the activity to a background service and put them into foreground
|
||||||
* state.
|
* state.
|
||||||
@ -164,8 +179,9 @@ public class BackgroundMode extends CordovaPlugin {
|
|||||||
Intent intent = new Intent(
|
Intent intent = new Intent(
|
||||||
context, ForegroundService.class);
|
context, ForegroundService.class);
|
||||||
|
|
||||||
if (isDisabled)
|
if (isDisabled) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
context.bindService(
|
context.bindService(
|
||||||
intent, connection, Context.BIND_AUTO_CREATE);
|
intent, connection, Context.BIND_AUTO_CREATE);
|
||||||
|
Loading…
Reference in New Issue
Block a user