No video

#3 Display Android notification at a particular time with Alarm Manager

  Рет қаралды 105,495

Lemubit Academy

Lemubit Academy

5 жыл бұрын

In this Android development lesson, you are going to learn how to schedule and display a notification at a particular time in the device. You can use this if you want to remind the user or just pop a notification sometime in the future. We are going to use the Alarm manager to schedule the notification. We are also going to make use of a Broadcast receiver to display the notification.
We are also going to create a notification channel so that the notification can be displayed on devices running Android 8.0 (API level 26) and above.
Documentation: developer.android.com/trainin...

Пікірлер: 196
@federicoairola9571
@federicoairola9571 4 жыл бұрын
Thank you, you saved my project! This is the only way to get things work... I tried with Stackoverflow methods and even with other KZfaq videos ways, but I always failed... Notifications display even after closing the app! Thank you! 😊
@LemubitAcademy
@LemubitAcademy 4 жыл бұрын
Hey Federico! I am glad it helped your project. :) For the notification you mentioned is not working on android 9, did you make sure you called the private method in the OnCreate, if that method isn't called, the notification channel wouldn't be created and would not work from Android 8 and above. I suspect that might be the issue in your case 🤔
@federicoairola9571
@federicoairola9571 4 жыл бұрын
@@LemubitAcademy I fixed the bug about Android 9, I made a silly type mistake in the channel ID. Thank you, your notification method rocks 😎
@hadapadakshay
@hadapadakshay 4 жыл бұрын
@@federicoairola9571 Does This repeat notification daily on specific time?
@federicoairola9571
@federicoairola9571 4 жыл бұрын
@@hadapadakshay nope dude, it shows your notification only once
@akashkumar7922
@akashkumar7922 4 жыл бұрын
@@federicoairola9571 Hey greatful to Know Thats its working in android 9 So can U please Share What u have done that its keep running in android 9 when app is killed also
@imadsaddik
@imadsaddik Жыл бұрын
Thank you so much, I have been having a lot of troubles with this since watching a lot of videos but when I watched yours it made it easier for me to grasp the concept.
@oderalon
@oderalon 3 жыл бұрын
I've been struggling to accomplish this for weeks. Reading documentation. Following instructions. Updating and even reinstalling Android Studio. But every time, there was something that didn't work. And now in five minutes you helped me solve the problem! It works perfectly now. 😌 Thank you! Merci! 謝謝! Vielen Dank! شكرا! Grazie! ధన్యవాదాలు! Dankegon! どうもありがとうございます!
@dhrutic1495
@dhrutic1495 3 жыл бұрын
This is what exactly I needed... Thanks for the amazing tutorial. Cheers!!!
@vpsaxman
@vpsaxman 3 жыл бұрын
Very clear and concise. Thank you!
@philipdanielgonzales9058
@philipdanielgonzales9058 4 жыл бұрын
I tried creating this kind of function in a real phone. It only works when the app is in the background. It does not work when you close the app (and I mean remove the app from the background process).
@Wang_dadi
@Wang_dadi 3 жыл бұрын
Very useful tutorial, you can't imagine how much I appreciate it. Subbing right now.
@TVSanus
@TVSanus 4 жыл бұрын
Perfect! Exactly what I needed!
@loizos3918
@loizos3918 2 жыл бұрын
Literally saved me, I have been searching for this for days. Can't thank you enough!
@LemubitAcademy
@LemubitAcademy 2 жыл бұрын
Glad I could help!
@Zekeziel-Reacts
@Zekeziel-Reacts 3 жыл бұрын
Thanks a million, this really helped me understand how reminders worked for a project I was working on.
@LemubitAcademy
@LemubitAcademy 3 жыл бұрын
You're very welcome!
@julietarodriguez7948
@julietarodriguez7948 4 жыл бұрын
Thank you man, i had a similar code and was not working because of a channel setup issue that i figured out thanks to your explanation.
@LemubitAcademy
@LemubitAcademy 4 жыл бұрын
Thanks Julieta, glad I could help.
@emremuslu7763
@emremuslu7763 3 жыл бұрын
Thank you so much! I found what I was looking for in this video.
@LemubitAcademy
@LemubitAcademy 3 жыл бұрын
Glad it was helpful!
@danielsantiagovasquez7425
@danielsantiagovasquez7425 4 жыл бұрын
Excellent explanation, very straightforward. Thanks! :)
@LemubitAcademy
@LemubitAcademy 4 жыл бұрын
Thank you Santiago! :)
@xvax
@xvax Жыл бұрын
Thank you ,Very clear and concise
@botrosyoussef3912
@botrosyoussef3912 4 жыл бұрын
You are awesome, too the point. I love your way of teaching.
@LemubitAcademy
@LemubitAcademy 4 жыл бұрын
Thank you Youssef. I appreciate that!
@BOFFNE
@BOFFNE 3 жыл бұрын
This is ace, thank you so much!
@Baku69895
@Baku69895 2 жыл бұрын
Excellent video and thank you!
@CodingDyan
@CodingDyan 4 жыл бұрын
You're the best man! :)
@jaweriajalil8587
@jaweriajalil8587 Жыл бұрын
Good job! it really help me to complete my assignment. TYSM!!
@bhggvghfg1075
@bhggvghfg1075 4 жыл бұрын
Thanks man, ur the best !!!
@Ash-td4sx
@Ash-td4sx 3 жыл бұрын
It's not notifying when i kill the app from recent/background app.. but you showed it still notifies when app is killed from recent/background apps. please suggest the solution.
@qiantingshao7693
@qiantingshao7693 3 жыл бұрын
Thank you so much! I hope you could teach us how to set a repeat alarm.
@convi346
@convi346 Жыл бұрын
Many thanks! Helped me alot :)
@user-uf2dl9uk7w
@user-uf2dl9uk7w 8 ай бұрын
Thank you. I don't know well English, but your code is so good to understand. This video is so useful
@LemubitAcademy
@LemubitAcademy 7 ай бұрын
Glad it helped and was useful 🙂
@chhatrapatikumar
@chhatrapatikumar 7 ай бұрын
​@@LemubitAcademyHey dude, can you make local schedule notification with datetime picker in jetpack compose please!!. Jetpack compose seems dead and thus buried, no one is using that, everyone is ignoring compose like their crush !! Hahaha !!.. I'm frustrated to find compose resources and tutorials, I think if I can't find tutorials then i have to move to XML !!.
@ovanquang5638
@ovanquang5638 3 жыл бұрын
thank you very very very much. Perfect
@haunguyen5790
@haunguyen5790 2 жыл бұрын
Tks for your support. Its help me so much
@jyrust1713
@jyrust1713 4 жыл бұрын
Thanks for a lot, i have a questions how we can get notif after 10 sec but continuously? I will get that for my workout thanks
@linhmai6266
@linhmai6266 4 жыл бұрын
Good video. Thank Bro!!
@cartoonist6012
@cartoonist6012 4 жыл бұрын
Thanks! New sub!
@jaysonlights6342
@jaysonlights6342 3 жыл бұрын
tested working :) thanks!
@fzn_redzone2811
@fzn_redzone2811 3 жыл бұрын
Amazing tutorial, but how would I do if I wanted to start a notification, at noon?
@manishpingale6558
@manishpingale6558 4 жыл бұрын
sir thank you so much but how we can give it sound when it pops
@gamelogger5233
@gamelogger5233 2 жыл бұрын
thank you it was great. how to open activity when user clicks on this notification?
@rx78quoter
@rx78quoter 4 жыл бұрын
Very Nice. Thanks.
@aarohimangal1189
@aarohimangal1189 4 жыл бұрын
Thanks worked all good in api 25 and above but dont why it didnt worked in below my min sdk is 21
@mukeshramharshyadav3255
@mukeshramharshyadav3255 4 жыл бұрын
Thank you man
@rudya.hernandez7238
@rudya.hernandez7238 3 жыл бұрын
Would this be useful for displaying a notification at a future date? Could be weeks, months, even over a year?
@sjjayaswal7621
@sjjayaswal7621 Жыл бұрын
Thanks for information 👍
@user-vl1rk7fi9n
@user-vl1rk7fi9n 3 жыл бұрын
Great! But I have one problem... I have tried to set the notification for date in long term but it doesnt work help please🙌
@aqibishaq885
@aqibishaq885 3 жыл бұрын
is there any need of some external library or android studio has this built in functionality of notification
@ViralShortsOfDuniya
@ViralShortsOfDuniya 3 жыл бұрын
Hi, Can i extend broadcast R to my main activity itself?
@pie5233
@pie5233 3 жыл бұрын
what can i do if i want the notification to start directly without 10 seconds after?
@johnmichaellacostales8622
@johnmichaellacostales8622 3 жыл бұрын
can it hold more than one time slots? i am working to a task scheduler app. Thanks i hope you answer
@dovdover
@dovdover 2 жыл бұрын
Thank you!
@MinhNguyen-ty6qm
@MinhNguyen-ty6qm 8 ай бұрын
Thanks you.
@ShahRukhKhan-fy1sz
@ShahRukhKhan-fy1sz 3 жыл бұрын
Very helpful tutorial please add a code that works on below api 26 level as well it would be very helpful
@SangPenyeruOfficial
@SangPenyeruOfficial 6 ай бұрын
can u add backend to push more notification ?
@FaizanAli-lw1nl
@FaizanAli-lw1nl 3 жыл бұрын
There is some problem in my code. I followed you exactly. But when i close my app it do not show me notification but when i open app again then it shows.
@zulkafal9341
@zulkafal9341 2 жыл бұрын
Looks great! Will it work and show the notification if the device is rebooted or restarted?
@elifececan8642
@elifececan8642 Жыл бұрын
thanks for the video, how can we create another notification with another message?
@pie5233
@pie5233 3 жыл бұрын
what if i want the notification to start directly without 10 seconds later?
@homoeochannel
@homoeochannel 2 жыл бұрын
Really, your code is working!
@amberahmed9769
@amberahmed9769 2 жыл бұрын
Can you plz tell about how to use multiple notifiction
@akshaychande9698
@akshaychande9698 4 жыл бұрын
this code is not working when my app is closed.Sir please suggest what can i do?
@ironjohn5349
@ironjohn5349 4 жыл бұрын
Hello. I have tried your code on a fragment, and instead of a button I have used switch. If switch is checked then it'll run your code to notify but it doesn't seem to work even on foreground. Here are the codes: public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){ final View rootView = inflater.inflate(R.layout.activity_reminder, container, false); timePicker = rootView.findViewById(R.id.time_picker); sw = rootView.findViewById(R.id.switch1); switchText = rootView.findViewById(R.id.switch_text); sw.setOnClickListener(this); switchText.setText(sw.getTextOff().toString()); timePicker.setEnabled(false); createNotificationChannel(); return rootView; } @Override public void onClick(View v) { if(v == sw){ if(sw.isChecked()){ switchText.setText(sw.getTextOn().toString()); timePicker.setEnabled(true); Intent intent = new Intent(getActivity(), ReminderBroadcast.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, intent, 0); AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE); long timeAtButtonClick = System.currentTimeMillis(); long tenSecondsInMillis = 1000 * 10; alarmManager.set(AlarmManager.RTC_WAKEUP, timeAtButtonClick + tenSecondsInMillis, pendingIntent); } else{ switchText.setText(sw.getTextOff().toString()); timePicker.setEnabled(false); } } } private void createNotificationChannel(){ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ CharSequence name = "ReadySetErgo"; String description = "ReadySetErgo Reminder"; int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel("notifyStretches", name, importance); channel.setDescription(description); NotificationManager notificationManager = getActivity().getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); } } My code doesn't have an error but I know there is a problem with it. I hope you can help. I already tried to search for answers, this is my last resort. Thank you.
@androiddeveloper6596
@androiddeveloper6596 2 жыл бұрын
hey brother
@mansoorghazi3077
@mansoorghazi3077 4 жыл бұрын
Excellent!
@LemubitAcademy
@LemubitAcademy 4 жыл бұрын
Glad you liked it!
@mysharow
@mysharow 4 жыл бұрын
Works fine in my kotlin app thanks. New Subscriber :)
@LemubitAcademy
@LemubitAcademy 4 жыл бұрын
Thank you :)
@bharatborhade6702
@bharatborhade6702 4 жыл бұрын
Not working in Oreo and above when app closed....help
@chetankhanna8975
@chetankhanna8975 4 жыл бұрын
It's telling me already have a pending vsync event.. Help please
@LemubitAcademy
@LemubitAcademy 4 жыл бұрын
Learning Java is important if you want to learn Android development, check a course on Java here: www.udemy.com/course/modern-java-programming/?referralCode=787BAD4910B603E322A1
@classicwaffles9508
@classicwaffles9508 3 жыл бұрын
what if i want the notification to appear every 22 of the month?
@talhaali6146
@talhaali6146 3 жыл бұрын
bro this alerm is pop up in notifications but i wanna show on full android screen
@ShymKTLMezun
@ShymKTLMezun 3 жыл бұрын
I have tried it, this alarm won't work with SDK 23+ you can search for doze mode in android
@user-zz8dv1py2l
@user-zz8dv1py2l 3 күн бұрын
thank you
@vinaybakle6443
@vinaybakle6443 3 жыл бұрын
How to make this notification clickable?
@abhishekseth8008
@abhishekseth8008 4 жыл бұрын
thanks . worked for me
@LemubitAcademy
@LemubitAcademy 4 жыл бұрын
Glad it helped
@MrMegaFrate
@MrMegaFrate 2 жыл бұрын
It works also on Android MarshMallow?
@ttttkk2
@ttttkk2 2 ай бұрын
how to make it work even if the phone is rebooted?
@singh6569
@singh6569 4 жыл бұрын
what if app is killed? custom broad receiver won't work!!!
@vaibhavpallod1023
@vaibhavpallod1023 4 жыл бұрын
Thanks bro
@sudheer-suri
@sudheer-suri 3 жыл бұрын
Nice tutorial, but when app is closed the notification is not popping up.
@doratnory9326
@doratnory9326 7 ай бұрын
can you please share progect full file to drive I try many time it's not working ❤ or send by Google drive
@adibalfainiafifi8335
@adibalfainiafifi8335 3 жыл бұрын
is this app run in background service?
@ammarhasan1383
@ammarhasan1383 3 жыл бұрын
nice video but I have a probleme >> when i close the app it wont trigger and when i reopen the app its get triggered
@spenweekapp4913
@spenweekapp4913 3 жыл бұрын
it s not working when app is killed...but its working when app is in background, Am i doing wrong ,I am using Android Pie
@abdulwalipk
@abdulwalipk 3 жыл бұрын
Well Done....
@manalmuhammad4180
@manalmuhammad4180 4 жыл бұрын
thanks very much it is good idea to use arrow to indicate the channel id to be the same name for createNotificationChannel () and NotificationMangerCompat
@fasirandomav
@fasirandomav 3 жыл бұрын
There are not solution for case when app is closed and process killed. Problem with broadcast receiver which work properly only locally. Also calendar with timer work properly only if app launched. App is killed = processes not working. If you want sent notification regardless of device state then you have to use firebase or other similar tools which can sent notification any device, using network.
@ehsanabid5716
@ehsanabid5716 2 жыл бұрын
Cannot resolve method 'set(int, long, long, android.app.PendingIntent)'
@abdulsametklncarslan7492
@abdulsametklncarslan7492 3 жыл бұрын
Thanks for tutorial, but it doesn't work for me when I close the app. What problem causes this do you think ?
@fasirandomav
@fasirandomav 3 жыл бұрын
There are not solution for case when app is closed and process killed. Problem with broadcast receiver which work properly only locally. Also calendar with timer work properly only if app launched. App is killed = processes not working. If you want sent notification regardless of device state then you have to use firebase or other similar tools which can sent notification any device, using network.
@rudya.hernandez7238
@rudya.hernandez7238 3 жыл бұрын
It doesn't work when the application is closed edit: Actually when the application is run through studio, it won't work when closed, but does work when started (and stopped) within the device itself. Must have to do with debugging.
@Kaje376
@Kaje376 3 жыл бұрын
Just had the same problem and your comment helped me, thank you! :)
@nurkhatijahht9690
@nurkhatijahht9690 2 жыл бұрын
can u describe how u do it ?
@kavi_geet9959
@kavi_geet9959 7 ай бұрын
Helped me…thanks
@ShahRukhKhan-fy1sz
@ShahRukhKhan-fy1sz 3 жыл бұрын
Not working on android 10 if you kill the app
@livesmartschool8164
@livesmartschool8164 3 жыл бұрын
It is not working if the app is not in the background
@bracketmutant7529
@bracketmutant7529 Жыл бұрын
Perfect, thank you
@shomyalkhan517
@shomyalkhan517 4 жыл бұрын
Copied all the code but didnot get any notification at all
@MystyXsoul
@MystyXsoul 2 жыл бұрын
Thank you so much T_T
@syafiqhumam
@syafiqhumam 9 ай бұрын
Thanksss
@user-ex5gi1cl1w
@user-ex5gi1cl1w 4 жыл бұрын
Kotlin version pls ?
@chaitanyapenjuri1615
@chaitanyapenjuri1615 4 жыл бұрын
For Android versions Nougat and Oreo, when I click button and close the app, the notification is not showing. Why?
@keltonholanda5740
@keltonholanda5740 4 жыл бұрын
i have the same problem, did you find a way to solve?
@chaitanyapenjuri1615
@chaitanyapenjuri1615 4 жыл бұрын
@@keltonholanda5740 The problem is in some devices, like One Plus series etc, the app is listed as "Battery Optimized" by default in system settings, so u need to whitelist the app/ask user permission from optimizing the app, then notifications will work.
@bogdanandronache9940
@bogdanandronache9940 3 жыл бұрын
I love u!
@oussamaml4161
@oussamaml4161 2 жыл бұрын
why not provide the source code in the description no one ever does that
@Hazimexx
@Hazimexx 2 жыл бұрын
i love you :)
@alokkumarpatro1395
@alokkumarpatro1395 4 жыл бұрын
this does not work in fragments
@user-qe6ek4ym2p
@user-qe6ek4ym2p 4 жыл бұрын
Is it possible to use alarmmanager on vivo Xiaomi mobile phone? On these phones, the clear process will not receive notifications, is there any solution?
@LemubitAcademy
@LemubitAcademy 4 жыл бұрын
Hmmm... for now I am not sure about that. Were you able to find a solution to that?
@ticherhaz
@ticherhaz 4 жыл бұрын
thank you so much! but how about api below than 26?
@LemubitAcademy
@LemubitAcademy 4 жыл бұрын
Hey 👋, It would still work with older APIs below 26, the only difference is that they would automatically ignore the channel ID.
@manishpingale6558
@manishpingale6558 4 жыл бұрын
@@LemubitAcademy thanks sir
@VinitPayalmusic
@VinitPayalmusic 3 жыл бұрын
Brother I'm doing the same as you did in the vid but my alarm doesn't work when i kill the app but i works fine when app is running. What yo do please I'm stuck in this problem for days also i want the notification to be swiped so I'm not using setForegroundService i really need your help.
@abdulsametklncarslan7492
@abdulsametklncarslan7492 3 жыл бұрын
Did you solve it ?
@VinitPayalmusic
@VinitPayalmusic 3 жыл бұрын
@@abdulsametklncarslan7492 no actually there is no problem in our code I was testing the app in custom rom devices like Xiaomi's miui and like Huawei etc These devcie manufacturers has enabled a battery saver feature that restricts the backround services of our apps.The only way of running a background service in these device is by removing your app from their optimization list .
@abdulsametklncarslan7492
@abdulsametklncarslan7492 3 жыл бұрын
@@VinitPayalmusic Thank you for your answer. I have decided to use Firebase Cloud Messaging to send notificiation when app is closed. But still I have a problem, I want user to select the notification date, hope there is a solution in FCM.
@kreandoappmail9036
@kreandoappmail9036 4 жыл бұрын
Hi Professor, if I reset the phone, the alarms are cleared. How can I fix this? This is my code: private void createAlarm(long timeInMillis) { AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this,Myalarm.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, new Random().nextInt(8),intent,0); //alarmManager.setRepeating(AlarmManager.RTC,timeInMillis,AlarmManager.INTERVAL_DAY,pendingIntent); alarmManager.setExact(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent); }
@abdremo
@abdremo 4 жыл бұрын
Kreandoapp Mail check on google there’s a way , something like REBOOT_Complex
@k.a.1077
@k.a.1077 4 жыл бұрын
bro, I want to ask for help, how about making realtime notifications from xampp and android using mysql, so I want to create an activity agenda, there are times when I can get out notifications on the backgroud in realtime, broou help me can y
@LemubitAcademy
@LemubitAcademy 4 жыл бұрын
Hi Anam, I don't really get the question :( .... you want real time data from MySQL?
@k.a.1077
@k.a.1077 4 жыл бұрын
@@LemubitAcademy yes
@k.a.1077
@k.a.1077 4 жыл бұрын
@@LemubitAcademy please help me
@lukecross5439
@lukecross5439 4 жыл бұрын
Is possible use this with to schedule to days (example, remember after seven days)?
@LemubitAcademy
@LemubitAcademy 4 жыл бұрын
Yes we can, it's just to increase the time. I might create a tutorial on this.
@lukecross5439
@lukecross5439 4 жыл бұрын
@@LemubitAcademy It would be very good, because then we wouldn't need to use cron jobs like Firebase PubSub, for example.
@EagleRex
@EagleRex 4 жыл бұрын
Hey! Great tutorial :) I have one question. I'll be really glad if you can help me with this. In the app, you have set time for 10 seconds from now. But in my app, I need to send two notifications at specific times. Let's say 3:30am and 2:15pm everyday. How can I send notifications at these specific times? Thanks in advance :)
@fzn_redzone2811
@fzn_redzone2811 3 жыл бұрын
Hey did you figure this out, I can’t figure it out?
@EagleRex
@EagleRex 3 жыл бұрын
@@fzn_redzone2811 No, I never figured this out. I tried many solutions but couldn't find the perfect one for the situation I listed in my comment.
@fzn_redzone2811
@fzn_redzone2811 3 жыл бұрын
@@EagleRex aww that sucks, but thanks for the fast reply
@fzn_redzone2811
@fzn_redzone2811 3 жыл бұрын
@@EagleRex if I figure it out, il let you know
@EagleRex
@EagleRex 3 жыл бұрын
@@fzn_redzone2811 Thanks! That will be really helpful :)
THIS Is How You Schedule Alarms on Android with AlarmManager
21:55
Philipp Lackner
Рет қаралды 37 М.
Советы по уведомлениям в Android
25:15
Android Broadcast. Все об Андроид разработке
Рет қаралды 9 М.
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
MrBeast
Рет қаралды 107 МЛН
НРАВИТСЯ ЭТОТ ФОРМАТ??
00:37
МЯТНАЯ ФАНТА
Рет қаралды 8 МЛН
Android. Пишем приложение - будильник.
23:08
Sergey Arkhipov Java Tutorials
Рет қаралды 30 М.
I've Built an Android App With Google's New AI Gemini
8:13
Philipp Lackner
Рет қаралды 116 М.
[Android] 15. Отправляем уведомления из приложения
9:29
BeTry | Программирование
Рет қаралды 4,1 М.
Alarm Clock with Notifications in Android Studio using Java | Alarm Manager
16:20
How to Send Notification in Android
14:15
Codes Easy
Рет қаралды 39 М.
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
MrBeast
Рет қаралды 107 МЛН