Notification in android games - android

In am developing a game using LibGdx for Android devices. I wish to have the notification as it is there in CANDY CRUSH game. This is to give a alert or a remainder if the user is not playing the game for some days.
Could you please help how to do this ? Any Pointer / Example would be a great help.

Aloupas is right about scheduling notifications. However, AlarmManager only works if the app has been run at least once to set the alarm and the phone hasn't been turned off. When the phone reboos/turns off, AlarmManager loses all of its pending stuff and they don't re-inflate when the system turns back on. I'd recommend the actual Android documents to check about Notifications in more broad sense, since there are a lot of types and a lot of solutions. Be warned, this stuff is dense, advanced, and finnicky as you move from API to API.
http://developer.android.com/guide/topics/ui/notifiers/notifications.html
There's also another thought: push notifications. If you want to manually alert your users about something (new levels added, double XP weekend, etc.), you'd want to register your app for push notifications. The easiest platform for managing this would be Parse. Parse is a flexible and easy to use HTTP library, and it includes DB support on Android, so it's a two-for-one. It also supports push notifications out of the box.
https://www.parse.com/
Cheers.

You can use AlarmManager to schedule a notification.
Here is an example how you can schedule an alarm manager:
http://smartandroidians.blogspot.com/2010/04/alarmmanager-and-notification-in.html
and in alarmManager Receiver you can construct the notification and show it to the user for example in this stackoverflow question:
How exactly to use Notification.Builder
Then in your Android Main Activity override onPause and onResume methods. OnResume cancel the alarmManager task and onPause start new alarmamanager.
Hope it helps

Related

How to create alarms on a flutter application for Android and iOS?

I'm trying to make an app where my user would be able set multiple countdown timers and be alerted when they are finished.
It needs to keep running and be precise even if the app is closed.
It needs to ring (default alarm sound) and vibrate. Only vibrate if sound is off. But do both if the device is on Do Not Disturb mode (after all he set the alarms himself).
It needs to show a the alarm name and have a button to dismiss/turn it off even if screen is off or if he is using other apps.
Previously I was using a BroadcastReceiver to open an activity that would do all that, but it doesn't seem to be working with flutter using a channel and native code on Android.
And according to this I should use high priority notifications instead.
And I'm also kinda new to Flutter, so I've been trying with channels, pendingintents, broadcastreceivers and a second native activity to show the alarm message with a dismiss button. It's not working. It shows the native activity only if the flutter app is on foreground.
I see there are a few plugins like intents, Alarm_manager and local notifications for flutter that should do it but I can't find a way to fulfill all my needs with them.
So I'm asking the pros: what's the best way to achieve this?
For Android, you can use android_alarm_manager_plus package. On iOS however, there's no equivalent feature of Android's AlarmManager as it recommends to create a calendar event or reminder for an alarm. As a workaround, you can use flutter_local_notifications for scheduled notifications.

How does Setting Up Notification when user leaves the app work?

I am new to coding. I am using Android Studio with Java. I spent the last 3 hours looking for how to set up a notification display at the top when the user leaves the app so they can always click on the notification when they want to return to the app but I couldn't find anything with that action I need.
The app tracks the users GPS and I want them to be able to always be aware that when the app is running it will continue to track their GPS. So my idea is to have a notification window pop up whenever they leave the app so they can be aware the app is running in the background.
Any help will be much appreciated! I am building this app on my own as a passion project and I am taking the Udacity Google Android course. I finished the course early and working on this app for fun. We didn't learn about Notifications or GPS tracking but I am doing my best to learn new things. Thank you for your patience and help!
My app code is here for easy viewing:
https://github.com/PoetryHorizon/eloteroMan2
Use a foreground Service. For any background logic, you should be using a Service anyway, and in Android Oreo and above, you're required to have it be a foreground Service, meaning it posts a Notification.
You can then add a PendingIntent to that notification set to reopen your app. See Android's Notification documentation on how to set a PendingIntent. You'll want to use PendingIntent.getActivity(), where the Intent you pass is new Intent(someContext, YourActivity.class).

Sending a push notification directly from the app

Not too experienced with mobile development, but I wanted to know if this was possible.
After the user installs the app (android or ios), the app should at least once a day "wake-up" and show a push notification to the user.
Is this possible?
If I understood you correctly, I believe that you need setup a recurring alarm using AlarmManager. You also need to setup starting alarm service on device reboot. You can write a method that does what you want so it get executed when the alarm runs e.g. show notification. The following links should help you:
Repeat Alarm Example In Android Using AlarmManager

Implement daily reminder notification in my app

I would like to ask some questions and getting your advise regarding to reminder notification, I have no experience in coding Java and this is my first trying develop Android app. My apologize for if my questions are duplicated.
The brief of what I need is : In my app, I have a setting for user to set Reminder and they can choose what time(from ListPreference) to keep remind them daily.
So my question is which one should I use
AlarmManager - as same as this Implement Notification Reminder? But I have a doubt on this, if the apps is not running(not opened) will the reminder still sending?
Firebase Cloud Messaging - If use FCM, how do I schedule and trigger to send push notification for reminder at specific timing to specific user?
Any Other simple method?
I have tried this method--> Write a function with nodejs to check the data change in Firebase to send notification to the app; deployed nodejs to Firebase Function. But the thing is i don't know how to schedule a job to keep changing data in firebase, it works when i manual keyin data. I think this is not the correct way, should not talking to database just to implement a simple daily reminder. Also this is not recommend method, right?
Hope I will get simplest advise from you all. Thanks
You could use the AlarmManager to set daily reminder but its not highly accurate after API Level 19(Kitkat)
And yes it will work when you app stops no issue but if your phone restarts you need to use the broadcast receiver which trigger when phone reboot and set the alarm again.
Or you could use this library Evernote android job which is very efficient when it comes to Scheduling and reminders.
I am using it in my app which have schedules on daily and weekly basis and its working perfectly.

ios alarm functionality limited?

I have an app which is on Android and iOS. I have added a local notification to fire every 24 hours at a time specified by the user of the app. In Android, the local notification functionality is exactly what I need, but in iOS it seems to lack the functionality I need, unless maybe I am missing something...
Lets say the user sets the time the notification is to fire to 11:00am. In Android, at 11AM, it will wake up the app, go to the broadcase receiver and I am able to run code in a method that calls out to an API to fetch the latest data. Once it gets the data, it posts the notification to the user.
In iOS, it seems the data being posted to the user has to be pre-scheduled. So I have to create the notification message during scheduling of the notification. What I need is to be able to do something more like the above example.
So the problem is that at the time of when the notification is scheduled to fire, I need to check for fresh data, not the day before...
Any suggestions?
The same functionality doesn't exactly exist on iOS.
You can setup a local notifications using the functionality of a UILocalNotification object. With this you can set fireDate, etc. which is sort of like a push notification without a server. You can send a message, add a badge on the app icon, play a sound, etc.
Now the issue is that the app doesn't get launched by the OS. The app simply registers a notification in the OS, which is then handled at the fireDate time. This means you won't be able to have a chance to check for data and verify whether to continue with the notification, etc.
UILocalNotification Class Reference

Categories

Resources