Android Quiet Notification - android

I am creating an app which plays audio in the background. I have created a background service and a persistent notification to indicate that the music is currently playing.
However, when I create the notification it feels to strong (e.g. the same as when a new txt or email comes in.) and slides down in the status bar. Instead, I would like the notification to just appear in the status bar without anything fancy. I see other apps which do this, but I cannot figure out how it is done.
I have experimented with different notification flags, but I haven't found one that works. I also don't see anything in the NotificationManager which would help.
Anyone know how to do this?

I wound up just re-using the same instance of the Notification object passed to NotificationManager rather than passing in a new one with the same ID.

Related

setFullScreenIntent still posting notification to the status bar

As per Android docs for setFullScreenIntent:
An intent to launch instead of posting the notification to the status bar.
Reality: Fullscreen intent is launched....but notification also gets posted to the status bar.
The screen is locked, so the user is not using the device.
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(android.R.drawable.ic_lock_idle_alarm)
.setContentTitle(timer.title)
.setContentText("Description!")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_REMINDER)
.setFullScreenIntent(pendingIntent, true) // tried with false too.
Any ideas why this doesn't work according to the docs?
I know I can remove the notification after it appears but the docs mention clearly that it should not appear.
This is reproducible both on a real device (Android 11) and on an emulator (Android 12).
I also notice the same thing with some other apps from the Play Store. They seem to use such notification (I can't know for sure but they appear on the lockscreen as fullscreen at least).
imho thats some old mistake in docs. I've never read this methods doc so carefully, but my experience says that full screen intent was/is always show Activity ADDITIONALLY to always-present notification. or will not, then freshly posted notification will appear as heads up, e.g. when user is using unlocked device at the moment of notification posting
also docs shows some use cases for such feature
Only for use with extremely high-priority notifications demanding the user's immediate attention, such as an incoming phone call or alarm clock
considering call: user didn't make any touch in GUI, instead just pressed home. Phone is ringing, how to close/reject/get back to managing Activity without Notification left? such Activity won't stay in recents history (noHistory), you may even press this home button accidentally and you don't even know in which app looking for sound source
imho this notification should also appear with started Activity, just like it happens. It isn't even visible on screen when user starts to use your extremely high-priority Activity. When job is done and Activity is finishing then Notification may also disappear, but when user won't take any decision and it is still crucial to pick some option - he need a fast option to get back to (even accidentally) "homed"/closed Activity

How to get all notification of all application have custom notification running

I'm a beginner. I have a problem about custom notification.
I want to read all information of normal notification and custom notification use RemoteView.
Example I want get all information about notification music(art cover, song, next, pause, back action)
I search very very much, but can't find the document I need.
If you know, please tell me.
Thank so much!
What you're looking for is a NotificationListenerService. From the docs:
A service that receives calls from the system when new notifications are posted or removed, or their ranking changed.
If you're specifically looking for ways to read Metadata and the music app is using a MediaSessionCompat, you can use MediaControllerCompat.getMetadata() to read the data off of the notification.
To display the actual content of the notification in your app, what you can do is get one of the many RemoteViews from the Notification object you received, then use this answer to display your notification.

Notification sent via PendingIntent does not show up

In one of Activity-derived class methods I'm trying to send a Notification, clicking on which will bring the Activity to foreground if my app is in background (not visible) right now. There are reasons why I don't use Service, but use Activity (that will hold PARTIAL_WAKE_LOCK) for that.
I remember Notification worked for me when I used it like this, but I sent it from Service. Now when I send it from Activity method and it doesn't show up, though I hear its notification sound.
So are there any reasons that prevent Notification show up sent from Activity method and how can it be solved?
Thank you.
I was not exactly precise copying Notification code sample. I removed setSmallIcon() call from code as I was too lazy to add icons. As a result system was really dropping my Intent, saying that no icon is provided for it and it'll be a crash in future releases.

How to handle NotificationBar in android

I tried the code form the answer of this question: How to put media controller button on notification bar?
By calling the
showNotification()
method my app gets closed. How to prevent this? And how can i handle that this method is just called if the mobile phone api is >= 16. Because i think it is just available since api 16.
I've read, that there is a solution for lower API:
import android.support.v4.app.NotificationCompat;
But i didn't got it working, so i just wanted to prevent calling it.
And can i delete the notification from the bar, by onDestroy() of my app?
The code on that page is for the most difficult case using RemoteViews, and it looks dubious anyway. (E.g. it creates a subclass of Notification with a constructor that creates another Notification.)
The normal approach is to use a NotificationCompat.Builder to build your notification, and NotificationManager or NotificationManagerCompat to show and cancel it. See the Notifications API Guide for details and example code.
Also see the Notifying the User documentation and the Notifications design guide.
Generally, your app should only show a notification when its activity is not visible. When the user taps on the notification, it should usually open the activity which should in turn cancel the notification.

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.

Categories

Resources