Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20285] Android - CloudPush - callback is called but notification isn't cleared

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-03-30T07:08:47.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterShawn Lan
AssigneeSrikanth Sombhatla
Created2015-07-31T19:57:46.000+0000
Updated2017-03-31T22:18:51.000+0000

Description

My setup is like the following:
	var CloudPush = require('ti.cloudpush');
	var rc = CloudPush.isGooglePlayServicesAvailable();
	if(rc == CloudPush.SUCCESS){
		CloudPush.retrieveDeviceToken({
		    success: deviceTokenSuccess,
		    error: function(){}
		});
		CloudPush.addEventListener('trayClickLaunchedApp', handler1);
		CloudPush.addEventListener('trayClickFocusedApp', handler2);
		CloudPush.addEventListener('callback', handler3);
	}
tiapp.xml
    <property name="acs-grouped-notification-message" type="string">You have $number$ unread messages</property>
If I receive a notification but leave it there without clicking it. Instead I launch my app from launcher. Then the callback function is called but the notification isn't cleared. If later I click the notification, it will launch the app but no callback is called. This is confusing to users. Preferable behavior would be: Once the callback is called, the corresponding notification should be cleared and the group message number should be reset. Or, like the iOS, the callback should never be called unless users click the notification or the app is in the foreground.

Comments

  1. Shawn Lan 2015-08-21

    Please re-open this case. I tested it again using your test case. The notification isn't cleared. To test it, you can't click the notification. Instead, launch the app from launcher. Then the callback is called, but the notification isn't cleared. I test it on my device - HTC One M7 - Android 5.0.2
  2. Shawn Lan 2016-01-27

    I tested again on Nexus 7, Android 6.0. I can still re-produce the issue. Please re-open this ticket. Maybe include a video or detailed steps on how you test it, so that we can make sure we are on the same page. Thanks!
  3. Srikanth Sombhatla 2016-02-26

    [~shawnlan], This is as per expected behaviour as mentioned in callback event documentation https://docs.appcelerator.com/platform/latest/#!/api/Modules.CloudPush-event-callback The notifications are not cleared in callback event because this event is fired on receiving a push, but not on user interaction. Also the docs says This will only be fired once per push notification. This is the reason the callback event will not be fired on next app open. But notification will be cleared either in trayClickFocusedApp or trayClickLaunchedApp events respecting the clear flag FLAG_AUTO_CANCEL mentioned in the notification. These events are fired when User clicks on your app's notifications. To handle graciously, you may want to invoke your notification handling logic in these methods as well. So I don't see this as a bug. That being said, I understand that clearing handled notifications should be unambiguous. You can open a feature request to provide an API to clear a particular notification or all notifications.
  4. Shawn Lan 2016-02-26

    "The notifications are not cleared in callback event because this event is fired on receiving a push, but not on user interaction. Also the docs says This will only be fired once per push notification. This is the reason the callback event will not be fired on next app open." Well, the expected behavior should be: The callback shouldn't be called if the user doesn't interact with the notification. Or, when the user interacts with the notification, the callback should be called again. Or, when the user interacts with the notification, the trayClick events should contain the payload. I would say it's a bug from user experience perspective.
  5. Shawn Lan 2016-02-26

    I found that if singleCallback is set to true, then when launching the app, the callback isn't called. Well, that can solve the issue here. But is this the expected behavior? It isn't in the documentation. Will it not be changed in the future? Thanks.
  6. Srikanth Sombhatla 2016-02-29

    Actually the purpose of callback event is well defined. It is used to inform that the app received a push. This behaviour can be effected by combination of flags like focusAppOnPush. See https://docs.appcelerator.com/platform/latest/#!/api/Modules.CloudPush-event-callback The trayClick events indeed contain the payload. Also what are the other flags you are using with CloudPush ?
  7. Shawn Lan 2016-02-29

    Yeah the problem is that the trayClick events don't contain the payload. At least not in the documentation. So I have to use the "callback" to show the message. What about my last question? When singleCallback set to true, the callback isn't called when launching the app from the drawer? It is not in the documentation either.
  8. Srikanth Sombhatla 2016-03-04

    [~shawnlan] trayClick* events contains payload. We need to update docs accordingly.
       Ti.API.info('Tray Click Focused App (app was already running)' + JSON.stringify(evt));
       {"type":"trayClickFocusedApp","source":{"pushType":"gcm","invocationAPIs":[],"bubbleParent":true,"showTrayNotification":true,"enabled":false,"__propertiesDefined__":true,"singleCallback":false,"_events":{"callback":{},"trayClickFocusedApp":{}},"focusAppOnPush":false,"debug":true,"showAppOnTrayClick":true,"showTrayNotificationsWhenFocused":false,"apiName":"Ti.Module"},"payload":"{\"android\":{\"icon\":\"app_icon\",\"sound\":\"default\",\"alert\":\"Push Notification Test\",\"badge\":2}}","bubbles":false,"cancelBubble":false}
       
    To invoke callback when app is launched you can set showTrayNotification to false. Please read this through before configuring your requirement https://docs.appcelerator.com/platform/latest/#!/api/Modules.CloudPush-event-callback This should not be effected by singleCallback
  9. Shawn Lan 2016-03-17

    Then update the docs, please. Here is my setup:
       var CloudPush = require('ti.cloudpush');
       	var rc = CloudPush.isGooglePlayServicesAvailable();
       	if(rc == CloudPush.SUCCESS){
       		//CloudPush.singleCallback = true;
       		CloudPush.retrieveDeviceToken({
       		    success: deviceTokenSuccess,
       		    error: function(){}
       		});
       		CloudPush.addEventListener('callback', receivePush);
       	}
       
    Launching the app without clicking the notification will fire the callback, as described in the original post. If setting CloudPush.singleCallback to true, launching the app without clicking the notification will NOT fire the callback. Test it yourself and see. I've read through the docs several times, but it seems your docs is not clear and complete.
  10. Srikanth Sombhatla 2016-03-24

    [~shawnlan] did you try setting showTrayNotification to false.
  11. Srikanth Sombhatla 2016-03-24

    PR for docs change https://github.com/appcelerator/titanium_mobile/pull/7880
  12. Shawn Lan 2016-03-24

    Thanks. I didn't try to set showTrayNotification to false. I didn't want that. Check my previous code. That's all my setup.
  13. Ashraf Abu 2016-03-30

    Docs for PR merged.
  14. Ashraf Abu 2016-03-30

    [~shawnlan] Is this still an issue?
  15. Lee Morris 2017-03-22

    [~shawnlan] Hi Shawn, I'm just wondering if you are still experiencing this issue? If not, would you like me to close the ticket?
  16. Lee Morris 2017-03-31

    Closing ticket as fixed, if there are any problems, please file a new ticket.

JSON Source