I am building a radio streaming app and was wondering what would be a good design for the back and home buttons.
Should the back button stop playing the music and quit the app? Should the home button allows the music to play in the background? Any suggestions?
The best design in my mind is not to override the default behavior of the back and home buttons.
My player puts a sticky notification into the notification area when play starts with a little persistent play arrow. When you click on the notification, it brings you to the radio controls so you can stop/pause the audio. This way, the user can leave the app using either the home or back key and you don't have to do fancy life cycle stuff to manage the state of the radio.
Don't override the native behavior unless there's a really good reason to. Add your own controls and leave the back button to do what it does. Keep in mind how frustrating it is when the ui suddenly does something unexpected.
Related
I have an app that plays media via MediaSessionCompat.
I create a notification for the Notification Drawer using NotificationCompat and post it using NotificationManagerCompat.notify, and it looks great. (See screenshot.)
My problem is with the lock screen. It only shows Play, Previous Track, and Next Track icons. I'm missing the controls to jump back and forward within the currently playing track. (See screenshot.)
I'm using MediaSession.setPlaybackState to specify the actions that are available, and I am including all the appropriate ones from PlaybackStateCompat for rewind, fast forward, skip to previous, and skip to next.
Is the lock screen configured differently than the notification? Or do developers simply have less control over the controls provided here?
Thank you in advance!
I'd like to create an app (actually just a menu) that should work just like the Android TV settings menu.
To be more specific, I'd like my app to cover only part of the screen and let any background video play on the remaining area (exactly like what happens with the settings menu).
Here's a picture of what I'd like to obtain:
This means that I should be able to:
open Live Channels
play some content
press the home button (at this point the channel will be playing in background behind the leanback launcher)
open my app, and have the background content continue playing
Of this, I just need to figure out how to obtain point 4, the rest is just how Android TV works by default.
Just to be clear, I don't want advices on how to create an app that plays a video and has a side menu, I want to integrate this menu inside the existing Android TV background videos feature.
Is it possible? I can't find any API for this.
For the app, you can do that using a transparent theme on the activity, that should keep the background visible (you can also decide to have a pseudo-transparent background to partially hide what's behind the activity, same way settings do).
The other question about playing the live channel on the background of the leanback launcher, I am not sure, but it sounds like it should be the standard procedure.
I'm developing a unity game for android and I'm looking for a way to pause the game whenever a notification pops up on the screen.
This is troublesome because pause menu button is at the top of screen and therefore lies behind the popup message and player cannot click on it.
I already implemented OnApplicationFocus() and successfully pause the game. However I also want to pause in these kind of occasions.
I found this answer for monitoring battery level but I'm looking for a general way for recognizing all kinds of popups.
I need to show the volume slider while casting an audio content to a Chromecast remote.
If I put the app to the background the slider is shown (see this).
The problem is that the framework does not show the slider when the app is not in the background.I guess it is because an application can decide to do something else.
I have tried to call
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI);
with no success: the slider that is shown does not have the Chromecast icon and does not report the current volume on the remote. In other words the slider is related with the local audio volume.
is there a way to ask the framework to keep showing the slider even when the app is in the foreground?
Edited
Actually the behaviour even with the VideoCast app is a bit inconsistent. On some phones it is enough to bring the app in the background and make the framework showing the volume slider. After that it will keep showing it even when the app is in the foreground. On other phones this does not work or it is not necessary because the slider is shown correctly.
There is a bit of improvement that can be made; when media is playing back (i.e. if it is not on pause), you can achieve what you want. To see how, you need to override onKeyDown; take a look at the CastVideos-android sample, in class VideoBrowserActivity and try that to see if it does what you'd like or not.
Since you want to show the Chromecast control instead of the generic music control, you need to call:
mAudioManager.adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME,
AudioManager.USE_DEFAULT_STREAM_TYPE, AudioManager.FLAG_SHOW_UI);
I want to realise an Android application that shows an always in foreground popup (even in front of the call screen) similiar to the one visible when you use the volume control keys. Sadly, neither toasts nor notifications are sufficient for my needs.
I experimented a lot with #android:style/Theme.Dialog, but the dialogs it creates are mostly not in the foreground.
How do I create what I need or how is the always-foreground popup implemented in Android?