• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Android push notification & asynchronous event

L

lukeis2k20

Guest
sorry but i have quite a few questions to drop in here all at the same time. here goes........

1 - if i go down the "push_local_notification(fire_time, title, message, data);" road...........

A - if the game is in the BACKground (or not running at all) when the time for a push notification comes will the asynchronous event still trigger?

B - can i use the async event to trigger the next notification? as in can i use the code below in the async

var fireTime = date_inc_hour(date_current_datetime(), 1);
push_local_notification(fireTime, "Hey!", "press this now!", data);


AND AND AND.............

2 - if i go down the "push_get_first_local_notification" / "push_get_next_local_notification" / "push_cancel_local_notification" road........

A - how do i set the timing of the notifications?lets say i want one at 30 mins, 60 mins, 90 mins and so on (obviously i dont want them to be so often but just for examples sake)

B - do i have to set them all in advance, as in if i have 50 notifications i have to set them all up in the queue every time the game is closed?


thank you all for any help / info given. any code or links to more info is very welcome but the info in the gamemaker studio guide / site is VERY limited on this subject
 
Last edited by a moderator:
Q

Quackertree

Guest
Example of Use
In this example we will send a local push notification using the following code:

Code:
var fireTime = date_inc_day(date_current_datetime(), 1);
var data = "daily_reward";
push_local_notification(fireTime, "Ahoy!", "Catch The Haggis Has A Present", data);
This will set a timer to "push" a notification to the device when one day has passed. When the day is up, if your game is either in the background or not running, a notification will be shown to the user with the given title and message (on iOS, the game name is shown and the title is ignored), and then an asynchronous Push Notification Event will be called. Note that if the game is in the foreground when the time for the notification comes, it will not be shown, but the asynchronous event will still trigger. In the event itself you would handle the callback something like this:

Code:
var type = ds_map_find_value(async_load, "type");
var status = ds_map_find_value(async_load, "status");
if status == 0
{
//error of some kind
var error = ds_map_find_value(async_load, "error");
show_debug_message("error=" + string(error));
}
else
{
if type == "register"
{
global.reg_id = ds_map_find_value(async_load, "reg_id");
}
else
{
var data = ds_map_find_value(async_load, "data");
if data == "daily_reward"
{
global.Gold += 1000;
}
}
}
NOTE: The variable async_load is only valid in these events, as the ds_map that is points to is created at the start of the event, then deleted again at the end, with this variable being reset to a value of -1.
I don't see how you cannot get all information you need from this. It seems straight-forward enough to me... :/
 
L

lukeis2k20

Guest
1 - (REMOVED AS ANSWERED)
2 - it does NOT say if another notification can be triggered from the async

did you read the question?
 
Last edited by a moderator:
L

lukeis2k20

Guest
the user guide text you pasted in here is NOT quite the same as mine for some reason

"Tapping the notification will start the game on the device and trigger an Asynchronous Push Notification event with a ds_map which can then be parsed to check the payload string and perform whatever action is required"
 
L

lukeis2k20

Guest
ALSO the second set of questions are NOT related to this, they are from "push_get_first_local_notification" / "push_get_next_local_notification" / "push_cancel_local_notification"
 
Q

Quackertree

Guest
1 - it does NOT say if the async will run if the game is in the BACKGROUND (as in will the async run even if the notification is not pressed)
2 - it does NOT say if another notification can be triggered from the async

did you read the question?
the user guide text you pasted in here is NOT quite the same as mine for some reason

"Tapping the notification will start the game on the device and trigger an Asynchronous Push Notification event with a ds_map which can then be parsed to check the payload string and perform whatever action is required"
*thump*

I literally underlined the part where it answers your question...

Either way, I agree it doesn't tell about the second part here, but this is common sense. Of course this works, it's just a piece of code that it's executing.
 
L

lukeis2k20

Guest
yeah, i see that having read the part and seeing the version you have is different to mine, thanks for that. as for the async running another notification i thought it would but so far it seems not to.

by the second part i mean......


2 - if i go down the "push_get_first_local_notification" / "push_get_next_local_notification" / "push_cancel_local_notification" road........

A - how do i set the timing of the notifications?lets say i want one at 30 mins, 60 mins, 90 mins and so on (obviously i dont want them to be so often but just for examples sake)

B - do i have to set them all in advance, as in if i have 50 notifications i have to set them all up in the queue every time the game is closed?
 
L

lukeis2k20

Guest
ALSO @Quackertree i just found this little section which makes me wonder if triggering the next notification in the async would work

"On Android, all notifications received when the app is not running/in background, will be stored, and the data delivered by the async event the next time the app runs"

if the async does not do anything until the game runs then it cannot be used to trigger the next notification. while it would trigger from a code point of view from a simple logic point of view it would not set the next notification to run until the app / game was opened
 
Q

Quackertree

Guest
Code will only run whenever your app is opened, so you won't be able to trigger another push notification without having the app being open, no. I thought you were talking about running that piece of code in the async event, which is just fine, you can run that code anywhere, really.

Either way; I have no clue about that second part, as I haven't done anything with that, ever. If the manual doesn't help you, you should try to look online for the manual (which is where I pulled my snippet from, anyway) and look there. That's really all the advice I can give you here.
 
L

lukeis2k20

Guest
If the manual doesn't help you, you should try to look online for the manual
the manual online is the same as the manual i have and i have looked all over online already before posting on here (because i am not retarded)
 
L

lukeis2k20

Guest
is there anyone in here who has any actual answers for me on this subject as opposed to just telling me to look at the manual which does not have all the answers i need?
 
L

lukeis2k20

Guest
1 - "When the day is up, if your game is either in the background or not running, a notification will be shown to the user with the given title and message (on iOS, the game name is shown and the title is ignored), and then an asynchronous Push Notification Event will be called"

this says the async will run if the app is closed / in the background.

2 - "On Android, all notifications received when the app is not running/in background, will be stored, and the data delivered by the async event the next time the app runs"

this says the exact opposite.

does anyone see why i an confused?

@Quackertree - these are BOTH from the online manual, this is why i am getting lost.
 
Last edited by a moderator:
L

lukeis2k20

Guest
@ShaunJS - HELP ME!!! lol (or tag someone in who can PLEASE!)
 
Last edited by a moderator:
Q

Quackertree

Guest
EEEERRRRRMMMMMM??????? ok then.
When referring to 2nd thing, I mentioned the 2nd thing in your quote, namely this:

2 - if i go down the "push_get_first_local_notification" / "push_get_next_local_notification" / "push_cancel_local_notification" road........

A - how do i set the timing of the notifications?lets say i want one at 30 mins, 60 mins, 90 mins and so on (obviously i dont want them to be so often but just for examples sake)

B - do i have to set them all in advance, as in if i have 50 notifications i have to set them all up in the queue every time the game is closed?
I have zero experience with this, and therefor cannot help you here.

Also thought that this answered your question:

Code will only run whenever your app is opened, so you won't be able to trigger another push notification without having the app being open, no. I thought you were talking about running that piece of code in the async event, which is just fine, you can run that code anywhere, really.
I'm pretty confident that "On Android, all notifications received when the app is not running/in background, will be stored, and the data delivered by the async event the next time the app runs" is true. I think they've messed up the first quote from the manual, as it IS true that the push notification will run, even though your app is not running / in the background.

There are more things in the manual which show that it'll only run once it opens, for example: "Note that if the game is in the foreground when the time for the notification comes, it will not be shown, but the asynchronous event will still trigger.", clearly giving away that the push notification will run only when the game is opened / in the foreground.
 
L

lukeis2k20

Guest
well, @Quackertree , thanks for the (very clear) clarification. i guess i will test it anyway as i wrote the code already so it would be kind of stupid not to at least try it since it is already written. i will post the results here once i have them for anyone else in the future to read.

next (if it does fail as i am now expecting it to do) i will have to create some kind of notification manager to deal with all this mayhem. once i have that working i will post the code for it on here for others in the future.

PS @Quackertree - i had a quick look through your blog and your game looks really good, both graphically and just interesting to play. i will keep my eye out for that once it is available on the play store.
 
Top