From 9c88bba925b2f322ed913e2dabe87db6e142a9c7 Mon Sep 17 00:00:00 2001 From: Nathan Kerr Date: Fri, 29 Mar 2019 16:09:45 -0700 Subject: [PATCH] Fix to only close the correct app rather than all background-mode apps If you had two apps using this plugin running, clicking "Close" on a notification for one would close both. --- src/android/BackgroundMode.java | 2 +- src/android/ForegroundService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/android/BackgroundMode.java b/src/android/BackgroundMode.java index e2fed28..ae8ada5 100644 --- a/src/android/BackgroundMode.java +++ b/src/android/BackgroundMode.java @@ -82,7 +82,7 @@ public class BackgroundMode extends CordovaPlugin { public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); IntentFilter filter = new IntentFilter(); - filter.addAction("com.backgroundmode.close"); + filter.addAction("com.backgroundmode.close" + cordova.getContext().getPackageName()); cordova.getActivity().registerReceiver(receiver, filter); } diff --git a/src/android/ForegroundService.java b/src/android/ForegroundService.java index 9c78454..e4ae337 100644 --- a/src/android/ForegroundService.java +++ b/src/android/ForegroundService.java @@ -208,7 +208,7 @@ public class ForegroundService extends Service { if (settings.optBoolean("allowClose", false)) { - final Intent clostAppIntent = new Intent("com.backgroundmode.close"); + final Intent clostAppIntent = new Intent("com.backgroundmode.close" + pkgName); final PendingIntent closeIntent = PendingIntent.getBroadcast(context, 1337, clostAppIntent, 0); final String closeIconName = settings.optString("closeIcon", "power"); NotificationCompat.Action.Builder closeAction = new NotificationCompat.Action.Builder(getIconResId(closeIconName), settings.optString("closeTitle", "Close"), closeIntent);