Foregroundservice startforeground doesn't show notification - android

I have a channel defined, and notification defined that I send to startforeground with notification Id different from 0.
I also searched in google lot, but I can't find- why startforeground doesn't show the notification??????
Please help!
It's really frustrating me!!!!!

I just solved it.
I tried the app on other real device and it worked, so in my phone (when I tried the first time) I deleted the app and clear its data and then ran the app again and its worked.

Related

Firebase push notification is not working properly when device is offline

I am implement a tap action on the notification and then i found out that when i am offline and triggering the notification. and when i am coming to online i am only receiving the last notification. and it is only happening in android
please help
I have read lot of solution but did not found any proper answer.
I assume you've read this then. Check notification's time to live first, and if you're sure that's not the cause, make sure you're using different notification ids for notifications, otherwise you'll replace the currently shown notification with a new one.
Answered a similar post here. This is working as intended as notification messages are always collapsible.

Push notification after onDestroy

I have learnt how to send a push notification, it works well but I need to send a notification to the user even after the app has been closed. So far I know how to send it while the application is running. How do you send a notification when app is in the background or when its even closed, on Android?
There are many answers to this, you could use a Service in background and through that you could do, that service would be running at all times.
If you want your notification to be popped up at some specific point of time, you can specifically use BROADCAST RECEIVER. And with the help of PENDING INTENT, you can easily achieve this task.
About all the above keywords stated, you can easily find in the documentation of Android online.
Hoping that I was helpful...
In case of any more queries... Do ask and clarify.
Thank you...

All scheduled notifications appear at once when restarting phone only on Android (Ionic framework)

Here is my issue: Let's consider for example that I have a function that schedules a notification every week. So five weeks after having installed my app, I would have had 5 notifications that would have been displayed (one every week). Then, I restart my phone (for whatever reason) and all the notifications that had been displayed during those five weeks appear all in once. I don't understand how come that the previous scheduled notifications appear all in once when I restart my phone? (By the way, I cancel those notifications after they have been displayed). This problem only appears on ANDROID, the same app on IOS works perfectly. So, how come those notifications appear? It's like they are never completely cancelled? I tried several variants to avoid this problem but it doesn't want to go away. Any ideas?
Thanks a lot!
PS: I am using this plugin for local notifications: katzer/cordova-plugin-local-notifications
I have found an answer.
iOS cancels the notifications after they have been triggered. Android does not. Therefore, if the users opens the app, let's say you have scheduled a notification to appear in two days, and then close it and don't reopen it, two days later he will get the notification as scheduled. But, if he never reopens the app, that notification will never be canceled on Android and the notification will re-appear every time you restart your phone. To be cancelled, the user has to reopen the app for the bit of code that you've written to cancel the notification could run. It is very annoying because the purpose of a notification (in my case at least) is to allow the user to get an information without opening the app. Fortunately on iOs, the notifications cancels themselves so it works perfectly.
Thanks to Nic Raboy fr his time and help.

Alerting the user from a service (Android)

So, i have a service working in the background (when the application is closed) which connects to internet every 2 minutes and gets some data from a database, and if something's wrong i want to alert the user with some kind of a beep tone and a message on the screen or even better in the notification bar. Is it possible to do this and if yes, how?
I think the nicest solution would be to use a SystemBar Notification.
Using the Notification.Builder you can add a custom sound to your notification using setSound(Uri sound).
What you think of is called ´Notification´ in Android. You can find more information here on how to create some.

startForeground() does not show my Notification

I am trying to make my Service running in foreground. I tried to use this example (please look for the section "Running a Service in the Foreground"), but startForeground() does not actually show my notification. And no exceptions is thrown. To make it shown, I need to use NotificationManager like here explained. With NotificationManager my notification works, but i'm not sure that my Service is foreground after this "silent" call to startForeground().
What can be wrong?
EDIT: I just tested this sample project that should demonstrate startForeground(), but it does not work! I use API v7.0, I tested it both on emulator and real device (SE Xperia Neo). Notification does not appear.
EDIT2: if i try to call setForeground() then i got a warning setForeground: ignoring old API call.
I also tried to use startForegroundCompat() as described here, but effect is absolutelly the same. I check if my service is foreground using ActivityManager.RunningServiceInfo as described here, and I see that my service is not foreground.
I just noticed that startForeground() doesn't show the notification icon if the id parameter is set to 0...
startForeground(0, notification); // Doesn't work...
startForeground(1, notification); // Works!!!
I hope that it could help someone stuck on this.
in addition to the best answer.
you should also check that have you called setSmallIcon.
On my android phone, I cannot get what I expected without calling setSmallIcon
Is your service a started service or a bound service? I had the same issue with a bound service, but starting the service before binding it allowed me to call startForeground(int, notification) with and have the notification show up.
This might be an old thread, but I'd like to add what I just learned which is not mentioned yet:
It is possible that a Service is still alive after stopSelf() is called because there are Activity that have bound to the Service. As a matter of fact, the startForeground() is just not going to show the notification nor giving any exception in this circumstance.
in my case there was no notification after startForeground(...) invoke because I used only .setSubText(...) for setting the message of it (because it is rendered with smaller font on most of devices). But some of devices Xiaomi Redmi Note 4 won't show any notification if You not set message by using .setContentText(...).
Hope that will help someone
DMitry. I have just suffered your problem and found the cause.
If your app is changing state of a COMPONENT PackageManager.setComponentEnabledSetting()) Android removes the service from foregraound and its notification icon.
Bug reported at Nov, 2011

Categories

Resources