I'm new with Android programming. I'm just wondering whether its possible to set up auto notification. For example, every morning at 8am, the app will send a notification to user about something. Is this possible? Which area/class of Android programming should I look at? Thanks!
You should have a look at the Alarm Manager. You will need to use either of the 'set' methods, and give it a PendingIntent that will perform a broadcast or start an intent service that wakes up just to show the notification. For the broadcast, you will need to have a receiver in your app, that makes a Notification and shows it.
Related
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
I have an application in which it receives the notification when fired from Backend. Now what I want to achieve is that the notification should disappear after 2 minutes if user has not clicked on it (even if my app is killed or background). I know that this can be achieved by using the Notification manager's setTimeoutAfter() but that will work only if am making my custom notification using Notifcation Manger.But i want to dismiss the Notification generated by System after 2 minutes.
Any kind of suggestion or help will be welcomed.
It is not possible to do that. The default system notification builder is pretty bare bones and will not handle it. The best you can do is set a delivery timeout so if the device was off it won't get the notification once it expires.
See https://firebase.google.com/docs/cloud-messaging/concept-options#when_to_use_platform_specific_keys (only works on Android and Web)
I wrote an app for Android L only that listens to USB connection using Broadcast Receiver.
This receiver fires a notification every time onReceive is called.
I think user would find it annoying so I would like to give user a chance of disabling it. I know in Android L user can disable this in Settings -> Sound & notification -> App notification but I would like to add this function on my notification itself.
So my question is, is it possible to add a checkbox on the notification and when checked, disables this notification with the App notification settings gets updated?
thanks
From android 4.1 and up you can use .addAction(R.drawable.icon, "Name", pendingIntent) on your Notification.Builder to add a button on the notification. This will launch the pending intent that you specified. There you can save a boolean value on sharedPreferences to enable or not the notifications which you will check before starting the notifications.
If you dont have any kind of ui and only need to call a service from the button, check here on how to achieve this.
I am trying to broadcast an EVENT_REMINDER in order to cause the system to popup a notification. Is it possible or do I have to hit the route of implementing a Sync Adapter? That seems too much for such a simple task. I know some broadcasts are protected (CALL, SMS) but this should not be the case.
Intent intent = new Intent();
intent.setAction("android.intent.action.EVENT_REMINDER");
sendBroadcast(intent);
Thanks in advance!
I don't want to pop a Notification I want to simulate an event reminder programmatically
I have no idea what you think an "event reminder" is that isn't a Notification -- every device on which I use the Calendar app, event reminders are Notifications. Also, please note that what you claim in your comment runs counter to your first sentence of your question, where you specifically state that you want to "popup a notification":
I am trying to broadcast an EVENT_REMINDER in order to cause the system to popup a notification.
Regardless, the AOSP calendar app will not respond to your broadcast. From the manifest, you need to have a content:// Uri in the Intent, and presumably that will need to point to an actual calendar entry. And I would not be surprised if devices that replace the AOSP calendar app with their own do not support the broadcast at all.
So in my app I'm looking to have the students class schedules and the times which they need to be in class.
When the app is turned off I still want the notification to pop up that their class is about to start (possibly vibrate).
This sort of functionality is very akin to an incoming text message or notification of something like an email. I was wondering how to implement that into an app?
You need a Service which can run when the app is not opened. You should also think about a BroadcastReceiver that listens to BOOT_COMPLETED
You will need to use the AlarmManager to set an alarm when you require the notification, possibly with the RTC_WAKEUP flag so the device will wake from a sleep. From your alarm receiver you will need to take a wake lock (if you used RTC_WAKEUP) and start a service that will use the NotificationManager to display a message to the user (very similar to the incoming SMS message).
As #WarrenFaith pointed out you will need to create a BOOT_COMPLETED receiver to re-establish the alarm after the phone is rebooted as they are not persistent.