Block Android Notification during night time - android

I am trying to find documentation or a cleaner way of not showing notification(programmatically) during nighttime (sleeping hours). I have a service that periodically checks if certain conditions are met and then I fire the notification. I would want to avoid this when the user is sleeping.

I don't really think you need to. If the user wants to block notifications, they'll put the device in Do Not Disturb mode which blocks all notification. I have one set to automatically turn on at night and off in the morning. Bonus- when the DND turns off, I get all the notifications I miss. This is a feature of the Android OS.
If you really wanted to do this- just check the time before you put up a notification. If its too late, don't fire it. Optionally, set an alarm for when you think its late enough, and decide if the user should see them now.

Do you mean to keep running the program at night without using notifications?
You only need to use WorkManager, JobScheduler or AlarmManager to achieve.

Related

Turned off "Allow background activity" setting stops location updates in foreground service

I have a foreground service requesting location updates and doing stuff with them.
When the app is not on screen, it still works because the service has an ongoing notification.
But there is a battery setting, at least on my samsung device, called "Allow background activity".
I wasn't paying attention to it because it says 'background', and as far as I know, as long as I have a foreground service with ongoing notification, my app is regarded by android as in foreground, and never in background.
But I've noticed that, if that setting is turned off, my ongoing notification is still there, but the gps icon disappears and location updates stop coming.
Is this normal behavior or I'm doing something wrong? Shouldn't my app be regarded as in foreground instead?
In case it is normal behavior, I'm aware now that I can detect this status with isBackgroundRestricted(), and I can use that to notify the user that they need to change it.
The other question is, is there a way to programmatically open the exact settings page where the user should make this change?
Thank you!
I had a similar question here. Short answer is I don't think there is an intent to go to the exact screen, but you can get the user there using android.provider.Settings.ACTION_APPLICATION_SETTINGS.

Confused about iOS notifications

I've read a lot about notifications in iOS now and I'm quite confused about how to reliably schedule notifications, actually. Let me explain my scenario:
I created an Android app that holds a fixed list of dates. The user can not add or remove dates, he can only view that list (garbage removal dates for my area). You can, however, configure that you want to be notified the day before. I've made that app so that when the device starts, a notification timer is started that fires at a certain time, checks whether there are pending items for the next day and if so, shows a notification. Then it re-schedules itself for the next day. So normally, the user doesn't need to open the app at all to receive notifications. He only opens the app once to configure his street, which triggers the first scheduled event, or to actually see the list of upcoming dates.
I'm now trying to port this app to iOS and I understand from what I've read that there's no way to replicate the way I'm doing stuff on Android. I understand that I can create up to 64 notifications for certain points of time in advance, but without the user opening the app at all I can not be sure to reliably schedule all the notifications I may need.
Is there a reliable way to simulate the described Android behavior? Or is there a way to force the user to open up the app once every 30 days or so?
In a nutshell no.
If applicable you can make notifications repeating, but if the dates are random and you can't repeat the notification then you can't schedule more than the limit.
You can't schedule your app to run and you can't force the user to do anything. All you can do is post some sort of notification for 30 days or whenever with some message that you hope will compel them to open your app.
If you have a valid use case for it in your app, you can enable a background mode such as a location change on a cell tower transition for example, then when your app runs in the background re-schedule the notifications. Or remote push, or background fetch etc. But even with background modes you cannot guarantee your app will actually run in the background, you can just help to increase the chances that it might and the different background modes have different degrees of usefulness in this sort of area.

How does an Android time based app work?

How does an Android alarm app or any other time based notifications app like Calendar, Clock, etc work? More specifically, how does it show up the notifications at exactly the time specified by the user? Does it constantly run in the background and as soon as the required time comes up, does it show the notification? Or does it schedule the notification in Android's kernel before exiting? I am working on an app that needs to give the user notifications at times specifies by him. I am not able to figure out how to do that.
Maybe what you mean is to create an alarm, you can see this example.

Notification in android games

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

Android Notification trigger when the application is in the background

All, in my new android application i need a notification to trigger if the app is not used for last four days. That is from the last use of application if 4 days gone and not using the application a notification need to come.
plz any help will be apreciated...
thanks in advance.....
You will have to manage it by yourself.
1.) Set a preference to the time you want the alarm to go off, it will save, even after reboot.
2.) you need RECEIVE_BOOT_COMPLETED permission and register a BroadcastReceiver in your manifest for the BOOT_COMPLETED
3.) just reset the alarm time to the time you need, from the preference.
I think that's very bad practise... but if you want to do it nevertheless, simply use AlarmManager.

Categories

Resources