Reputation: 6297
Im experiencing a bad behavior using cordova on android, while developing with ionic framework, together with ngCordova plugins. With the PushPlugin plugin, Im able to receive notifications using GCM. When the app is in background and a notification is received, I can dismiss it without entering the app, but then, when I launch the app Im not aware of the new data received (& dismissed) is there a way to still have the data? I need it since its not only a notification, but also data I need to show on the UI later on.
Upvotes: 2
Views: 683
Reputation: 1848
You could achieve this behavior by modifying the plugin to cache the content from the server if application is in background. That way you will get the message even if the notification was dismissed. Read my answer on modifying the plugin.
Modify this function by adding
PushPlugin.sendExtras(extras)
that will send the data regardless of whether the app is in foreground or background.
protected void onMessage(Context context, Intent intent) {
Log.d(TAG, "onMessage - context: " + context);
Bundle extras = intent.getExtras();
if (extras != null)
{
if (PushPlugin.isInForeground()) {
extras.putBoolean("foreground", true);
}
else {
extras.putBoolean("foreground", false);
if (extras.getString("message") != null && extras.getString("message").length() != 0) {
createNotification(context, extras);
}
}
// call sendExtras always
PushPlugin.sendExtras(extras);
}
}
Upvotes: 0
Reputation: 86
This isn't possible unfortunately. If the user clicks the notification you can execute some code. If the user dismisses it, your app will never know.
How I would build that functionality is have a database that holds all the information that a user needs to see. When the user sees the information (by opening a notification or otherwise), make a call to the sever and mark that content as read.
That way you could call your server when the app launches to get a list of content to show the user. If a notification is clicked you could take them directly to that data and then hit the server and mark it as 'viewed', or whatever.
Hope that helps, Good luck!
Upvotes: 1