Open patriciapg93 opened 9 years ago
Put this in your app.js:
/* When the app is started */
var lastData = gcm.getLastData();
if (lastData) {
... view the notification ...
gcm.clearLastData();
}
/* And when the app is resumed */
Ti.Android.currentActivity.addEventListener("resume", function() {
var lastData = gcm.getLastData();
if (lastData) {
... view the notification ...
gcm.clearLastData();
}
});
Okey, now it works. I was calling the function twice, my bad.
The problem I have now is that sometimes, when I execute the app and I close it, I don't receive the push. I must open it again (still not receive push) and close it, then I can receive push again. It seems to enter twice in the success function because I can see the Ti.API.Info duplicated (the second one takes a few seconds to appear), but now I'm calling this function once.
Any clue? What am I doing wrong?
Thank you for your time!
Maybe check the output of adb logcat
and verify whether the push is actually received by the device (or simulator).
I've checked the logcat and when I send a push, I can see this:
09-15 12:09:05.795: I/GCM(1534): GCM message [app_package] 0:1442311746300784%686fe507f9fd7ecd
09-15 12:09:05.895: V/GCMBroadcastReceiver(20289): GCM IntentService class: nl.vanvianen.android.gcm.GCMIntentService
But nothing else, and I don't receive the notification. This happends when I close the app before the second success info..
When I receive push the ouptut is:
09-15 12:13:28.785: I/GCM(1534): GCM message [app_package] 0:1442312009285689%686fe507f9fd7ecd
09-15 12:13:29.465: V/GCMRegistrar(22499): Setting the name of retry receiver class to nl.vanvianen.android.gcm.GCMBroadcastReceiver
09-15 12:13:29.465: V/GCMBroadcastReceiver(22499): GCM IntentService class: nl.vanvianen.android.gcm.GCMIntentService
09-15 12:13:29.485: V/GCMBaseIntentService(22499): Intent service name: GCMIntentService--1
09-15 12:13:29.485: D/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [29,390] Push notification received
09-15 12:13:29.495: D/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [5,395] Message key: Type value: 1
09-15 12:13:29.495: D/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [1,396] Message key: from value: 299548822026
09-15 12:13:29.495: D/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [1,397] Message key: title value: Ajedrez Viladecans
09-15 12:13:29.495: D/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [1,398] Message key: message value: ¡Tienes un nuevo cuestionario!
09-15 12:13:29.495: D/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [1,399] Message key: channelID value: 6045
09-15 12:13:29.495: D/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [2,401] Message key: collapse_key value: do_not_collapse
09-15 12:13:29.565: E/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [67,468] Invalid setting priority, should be int, between PRIORITY_MIN (-2) and PRIORITY_MAX (2)
09-15 12:13:29.575: D/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [5,473] Creating notification...
09-15 12:13:29.585: I/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [16,489] Group: MyNotificationGroup
09-15 12:13:29.595: I/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [7,496] LocalOnly: false
09-15 12:13:29.595: I/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [1,497] Priority: 0
09-15 12:13:29.595: I/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [2,499] Vibrate: true
09-15 12:13:29.595: I/GCMIntentService(22499): (IntentService[GCMIntentService--1]) [1,500] Insistent: false
Strange, you should see the Push notification received
message.
I think it is because of the registrationId. If it's entering twice in the success function but I quit the app before the second success then it's like the first registration doesn't exists and the second one fails or something, so I'm not able to receive any push.
I'm trying to figure out why is the app trying to register for push twice.
Hi,
I want to show specific view when the user touches the notification. It works when the app is in foreground and background, but it doesn't when the app is closed (it only opens the app and). In the logcat I can't see it never entering in the lastData if, I don't know why.
Is there a way to achieve this?
Here is my code, anyway: