mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2025-12-13 09:53:22 +00:00
JS interface to customize the notification on Android
This commit is contained in:
@@ -33,6 +33,7 @@ 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 {
|
||||
|
||||
@@ -42,6 +43,9 @@ public class BackgroundMode extends CordovaPlugin {
|
||||
// Flag indicates if the plugin is enabled or disabled
|
||||
private boolean isDisabled = false;
|
||||
|
||||
// Settings for the notification
|
||||
static JSONObject settings;
|
||||
|
||||
// Used to (un)bind the service to with the activity
|
||||
private ServiceConnection connection = new ServiceConnection() {
|
||||
|
||||
@@ -80,6 +84,11 @@ public class BackgroundMode extends CordovaPlugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase("configure")) {
|
||||
settings = args.getJSONObject(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase("enable")) {
|
||||
enableMode();
|
||||
return true;
|
||||
|
||||
@@ -32,6 +32,9 @@ import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@@ -126,15 +129,18 @@ public class ForegroundService extends Service {
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(
|
||||
context, NOTIFICATION_ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
|
||||
String title = "App is running in background";
|
||||
JSONObject settings = BackgroundMode.settings;
|
||||
|
||||
Notification.Builder notification = new Notification.Builder(context)
|
||||
.setContentTitle(title)
|
||||
.setContentText(title)
|
||||
.setTicker(title)
|
||||
.setContentTitle(settings.optString("title"))
|
||||
.setContentText(settings.optString("text"))
|
||||
.setTicker(settings.optString("ticker"))
|
||||
.setOngoing(true)
|
||||
.setSmallIcon(getIconResId())
|
||||
.setContentIntent(contentIntent);
|
||||
.setSmallIcon(getIconResId());
|
||||
|
||||
if (settings.optBoolean("resume")) {
|
||||
notification.setContentIntent(contentIntent);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT < 16) {
|
||||
// Build notification for HoneyComb to ICS
|
||||
|
||||
Reference in New Issue
Block a user