Commit 78a0e581 by Sebastián Katzer

Callback function will be called in foreground

parent cc410871
......@@ -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
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment