Loading src/android/LocalNotificationReceiver.java +33 −1 Changes for src/android/LocalNotificationReceiver.java: 33 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -90,9 +90,12 @@ public class LocalNotificationReceiver extends BroadcastReceiver { .setSmallIcon(options.getIcon()); try { if (!context.getPackageName().equalsIgnoreCase(((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningTasks(1).get(0).topActivity.getPackageName())) { if (isInBackground(context)) { // app is in background notification.setDefaults(Notification.DEFAULT_SOUND); } else { // exec foreground callback invokeForegroundCallback(options); } } catch (Exception e) { // missing GET_TASKS permission Loading @@ -107,4 +110,33 @@ public class LocalNotificationReceiver extends BroadcastReceiver { */ notificationMgr.notify(id, notification.build()); } /** * Gibt an, ob die App im Hintergrund läuft. */ private boolean isInBackground (Context context) { return !context.getPackageName().equalsIgnoreCase(((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningTasks(1).get(0).topActivity.getPackageName()); } /** * Ruft die `foreground` Callback Funktion auf. */ private void invokeForegroundCallback (LocalNotificationOptions options) { String function = options.getForeground(); if (function != null) { LocalNotification.webView.sendJavascript(function + "(" + options.getId() + ")"); } } /** * Ruft die `background` Callback Funktion auf. */ private void invokeBackgroundCallback (LocalNotificationOptions options) { String function = options.getBackground(); if (function != null) { LocalNotification.webView.sendJavascript(function + "(" + options.getId() + ")"); } } } No newline at end of file Loading
src/android/LocalNotificationReceiver.java +33 −1 Changes for src/android/LocalNotificationReceiver.java: 33 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -90,9 +90,12 @@ public class LocalNotificationReceiver extends BroadcastReceiver { .setSmallIcon(options.getIcon()); try { if (!context.getPackageName().equalsIgnoreCase(((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningTasks(1).get(0).topActivity.getPackageName())) { if (isInBackground(context)) { // app is in background notification.setDefaults(Notification.DEFAULT_SOUND); } else { // exec foreground callback invokeForegroundCallback(options); } } catch (Exception e) { // missing GET_TASKS permission Loading @@ -107,4 +110,33 @@ public class LocalNotificationReceiver extends BroadcastReceiver { */ notificationMgr.notify(id, notification.build()); } /** * Gibt an, ob die App im Hintergrund läuft. */ private boolean isInBackground (Context context) { return !context.getPackageName().equalsIgnoreCase(((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningTasks(1).get(0).topActivity.getPackageName()); } /** * Ruft die `foreground` Callback Funktion auf. */ private void invokeForegroundCallback (LocalNotificationOptions options) { String function = options.getForeground(); if (function != null) { LocalNotification.webView.sendJavascript(function + "(" + options.getId() + ")"); } } /** * Ruft die `background` Callback Funktion auf. */ private void invokeBackgroundCallback (LocalNotificationOptions options) { String function = options.getBackground(); if (function != null) { LocalNotification.webView.sendJavascript(function + "(" + options.getId() + ")"); } } } No newline at end of file