-
Notifications
You must be signed in to change notification settings - Fork 1.9k
allow forceShow option to always notify (android only atm) #178
Conversation
@@ -88,7 +88,7 @@ protected void onMessage(Context context, Intent intent) { | |||
Bundle extras = intent.getExtras(); | |||
if (extras != null) { | |||
// if we are in the foreground, just surface the payload, else post it to the statusbar | |||
if (PushPlugin.isInForeground()) { | |||
if (!FORCE_SHOW && PushPlugin.isInForeground()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you be getting this option in a way similar to this?
SharedPreferences prefs = context.getSharedPreferences(PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
boolean force_show = prefs.getBoolean(FORCE_SHOW, false);
Accessing FORCE_SHOW directly is only targeting the String
defined in PushConstants, and a String
is always true'ish, thus making it not an option to decide on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like you are right ^^ give me a minute to update
@AdriVanHoudt can you add the necessary documentation to the README.md file and then rebase so the PR merges cleanly? They I should be able to merge this. |
Will do |
6d88b7c
to
2b842d9
Compare
Done |
@AdriVanHoudt actually I did some testing of this today and it's not quite ready for merging. Take a look at my comments in the code. |
@macdonst did you add comments or do you mean the inline ones? Because I don't see any added on github atm |
// if we are in the foreground, just surface the payload, else post it to the statusbar | ||
if (PushPlugin.isInForeground()) { | ||
if (!forceShow && PushPlugin.isInForeground()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have two variables we need to account for 4 different cases.
- forceShow = false & PushPlugin.isInForeground() = true
- should set foreground boolean to true and then fire the
notification
event.
- forceShow = true & PushPlugin.isInForeground() = true
- should set foreground boolean to true, fire the
notification
event and show the notification in the shade
- forceShow = false & PushPlugin.isInForeground() = false
- should set foreground boolean to false and then show the notification in the shade
- forceShow = true & PushPlugin.isInForeground() = false
- should set foreground boolean to false and then show the notification in the shade
Obviously 3 and 4 are the same so we can handle that in an else but we need something like this un-optimized code:
if (!forceShow && PushPlugin.isInForeground()) {
extras.putBoolean(FOREGROUND, true);
PushPlugin.sendExtras(extras);
} else if (forceShow && PushPlugin.isInForeground()) {
extras.putBoolean(FOREGROUND, true);
PushPlugin.sendExtras(extras);
// Send a notification if there is a message
String message = this.getMessageText(extras);
String title = getString(extras, TITLE, "");
if ((message != null && message.length() != 0) ||
(title != null && title.length() != 0)) {
createNotification(context, extras);
}
} else {
extras.putBoolean(FOREGROUND, false);
// Send a notification if there is a message
String message = this.getMessageText(extras);
String title = getString(extras, TITLE, "");
if ((message != null && message.length() != 0) ||
(title != null && title.length() != 0)) {
createNotification(context, extras);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't case 2) cause redundant behaviour? The notification
event would be possibly triggered twice (one by the receipt of the message, and another by the click handler on the notificaton itself). I'm not saying that's wrong, I just think something else is needed to differ from both events, as both data
objects will have the same properties as of right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Case 2 is wrong imo, the notification event should only be fired when actually clicked on the notification, as @fredgalvao said this could cause double events atm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you both mean. Remember that was vaguely pseudo code I posted. I still think we'd need to take care of case 2 when the information pushed to the device does not include a title or message parameter. Perhaps the developer wants to silently push some info to the device and still trigger the notification event. So more like:
if (!forceShow && PushPlugin.isInForeground()) {
extras.putBoolean(FOREGROUND, true);
PushPlugin.sendExtras(extras);
} else if (forceShow && PushPlugin.isInForeground()) {
extras.putBoolean(FOREGROUND, true);
// Send a notification if there is a message
String message = this.getMessageText(extras);
String title = getString(extras, TITLE, "");
if ((message != null && message.length() != 0) ||
(title != null && title.length() != 0)) {
createNotification(context, extras);
} else {
PushPlugin.sendExtras(extras);
}
} else {
extras.putBoolean(FOREGROUND, false);
// Send a notification if there is a message
String message = this.getMessageText(extras);
String title = getString(extras, TITLE, "");
if ((message != null && message.length() != 0) ||
(title != null && title.length() != 0)) {
createNotification(context, extras);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That fixes it well enough for me, but not for all cases... Well, if anything the user can always rely on the notId and check for duplicate events, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works, my train of thought was that when there is an actual notification shown don't fire the event but, forceShow would not affect this when there is nothing to show
@fredgalvao what cases aren't covered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure of the practical cases, but in theory one could send a push notification with message === null
and still want it to be shown with something else (like a big picture, or a summaryText, or whatever else he might provide other than message).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am correct at least a message is required to show any notification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, the snippet @macdonst provided already contains the "message OR title" piece.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update today to match these comments
@AdriVanHoudt just finished adding them. Also, when I had my OnePlusOne with the app running with your code I never got a notification event via JS or anything in the notification shade. |
Ok updated, only thing different then then the last code @macdonst proposed is that when not in foreground and no title/message it will send the extra data, which it doesn't do now |
allow forceShow option to always notify (android only atm)
Hey guys, I'm trying to get this to work, however the forceShow option doesn't seem to be working. I've tried to pull down the most recent changes, but it doesn't look like it's working on my N6. |
It is working for me when pulling directly from github in my config.xml |
@AdriVanHoudt thank you so much, your a god send. I had to add that into the config.xml to get it working. For whatever reason, "cordova plugin add https://github.com/phonegap/phonegap-plugin-push" wasn't pulling it in. In a side related question, what's the best way of displaying a confirmation popup if the app is in the foreground? I've found that $ionicPopup and confirm() doesn't work, the popup never displays. I was trying to ask the user if they would like to be redirected after receiving the notification, but it doesn't seem like anything is working. So for now, my work-a-around if to just always show a notification even if the device is in the foreground, then if they click the notification it redirects them. Any thoughts? |
Np :D I do not recoomend it though, why I asked for an eta on a release. And implementation depends on the app but you do know the notification event only fires when the notification is actually being clicked right? Unless it is only data or no forceShow and in foreground. |
@AdriVanHoudt Yes, that's the behavior I was aiming for. I was trying to only redirect to the new view if the user wanted to get to that view. The issue that I'm running into is that confirm() and $ionicPopup aren't displaying a popup when foreground === true, alert works fine so I know it's firing, but I'm not sure what the issue is with why confirm or $ionicPopup don't work. I was wondering if anyone had similar issues or had found something else that works. I was thinking the only other way is to use $watch to fire the $ionicPopup after I change the value of some $rootScope variable. |
@chriseckman I have no experience with $ionicPopup sorry :/ I redirect to a certain state on notification click and that works |
@AdriVanHoudt I'm going to get a 1.4.0 out this month but an exact day is hard to pick right now as I'm at and off site this week and Cordova Face to Face meeting next week. |
Maybe do a prerelease? I don't want to set my dependency to the GitHub URL that fetches the master branch |
@macdonst sorry to bug you but any eta on a release? Just can't wait for the new features ^^ |
Hey guys, another question. Finally got around to working setting up the iOS app with APN and I'm wondering if any has a workaround for the notifications not displaying if the iOS app is in the foreground? Is there another plugin that would work for iOS? |
you can probably add an option for this as well (not really sure though), see https://github.com/phonegap/phonegap-plugin-push/blob/master/src/ios/AppDelegate%2Bnotification.m#L65 (just a guess though) |
@AdriVanHoudt releasing today. |
🎉 |
@macdonst I think you missed this PR in the changelog ;) |
@AdriVanHoudt does |
my app not Show notification when application is in foreground, could help me find the problem. *my code in server is por example * var registrationIds = []; *and my code in aplicattion is * var push = PushNotification.init({
|
This thread has been automatically locked. |
fixes #76
(not sure if done completely right though :D)