Show Notification if app is playing - android

I wrote an streaming app and want an notification if the stream is playing.
How I can code it? In general the stream starts via an activity. Is it possible to make the notification showing if the activity plays?

You could create a notification when it starts and cancel the notification when it stops

Related

Android O : Notification channel for Incoming call

Introduction of notification channel allow many apps to remove their notification settings in app and redirect to device settings. Which is quite easy for developers as the framework itself will handle notification sounds.
Incoming call ringtones can be played via Ringtone manager or Media player. We cant play incoming call ringtone using notification because notification sound stops when the notification tray is opened.
Initially i created notification channel with IMPORTANCE_LOW so that there is no sound for incoming call notifications. There may be situation where user can assign sounds to incoming call notification where both sounds are played (sound set by notification channel and Incoming call ringtone which is handled by app).
This is a big problem for all calling apps. Can any one have solution for it ?

MediaStyle Notification not working properly

I want to create a MediaStyle Notification. I followed the official guide but I am facing some problems.
The notification is shown when I am starting the playback service as a foreground but
the play/pause button does nothing
the content activity is not shown if you click the notification
the playback service is not stopped when a swipe gesture happens
How can I solve this? Here is my MediaBrowserServiceCompat class. The notification is shown via showNotification() in onPlay().

Android push notification stop repeating sound on activity resume

I am implementing an app that receive push notifications. I have used flag Notification.FLAG_INSISTENT to continuously play sound until user drag notification panel. But I want to stop the sound on app resume rather than on dragging notification panel.
According to documentation, for notifications with FLAG_INSISTENT audio will be repeated until the notification is cancelled or the notification window is opened.
So when you resume your activity you can cancel your notification. if you want it to stay in the notification window, then redisplay it again without sound and the insistent flag.

Custom notification bar hiding the image when it is clicked

I am making a Radio like app in Android, in which I need to show the current playing channel in the notification bar with "Play/Pause" buttons. so what i need to do is that when user click on pause button song should be paused and play image should be displayed. I have done doing pause for sound from notification bar but now i need to show the play image instead of pause image, and i also need to put the seek bar to control the volume for music. Thanks in advance.
To update a notification, you simply call notificationManager.notify() again and pass it the same id that you gave it last time. if there's an existing notification with that id, it will update that one with the new information.
Typically for music playback or other persistent behaviors that the user should have control over, a foreground service is used. You use a regular Service and call startForeground(), passing it an id and a notification just like you would for NotificationManager. The benefit of this approach is that Android is less likely to terminate your service if it starts looking for processes to clean up as long as your service is running in the foreground. Updating the notification works the same way: call startForeground() again with the same id and a new notification object.

How do i remove a foreground notification in Android Lollipop?

I'm looking to stop/dismiss a foreground notification for a service for a mediaplayer, much similar to Google's implementation for Google Music.
For instance in Google Music, if you are playing music then the the notification cannot be swiped away. However if you pause the music it can.
This is completely different to how it is implemented on Android 4.4, where the notification starts only when you leave the app and removes itself when you go back into the app. I can't see how to implement this either considering the requirements for a service to have a notification.
Any help would be much appreciated.
How do i remove a foreground notification in Android Lollipop?
You can remove your own foreground Notification by calling stopForeground() from your Service, that called startForeground().
For instance in Google Music, if you are playing music then the the notification cannot be swiped away. However if you pause the music, you can swipe it away.
Presumably, they are updating the setOngoing() value for the Notification based upon whether or not the music is playing.
You can also remove the notification in a tricky way:
start 1st service with startForeground(1, new Notification());
start 2nd service with startForeground(1, new Notification()); and immediately stop it
As a result 1st service is still running in foreground but the notification is gone thanks to stopping 2nd service. I've found it by accident :).

Categories

Resources