Android Audio manager and volume screen - android

When you push the volume up or down key on the side of your phone, a volume notification pops up on the screen notifying you of the volume change. What is like to know is, could you make an app that replaces that notifying screen? Without making your app just appear over it?

Related

Use MediaButton to control foreground app (no audio) with audio in background

I want to use the media buttons to control a foreground app, but not for audio use.
So the goal is to detect button clicks to do certain things in the app.
I can achieve that by using MediaSession and the MediaButtonReceiver. see here
The problem is that when the app is used, often users play music in the background, so the audio focus of the background app takes over the MediaSession and i cannot control my app anymore.
Is there a way to achieve that? Directly listening for button clicks with onKeyDown does not seem to work.
sadly there is no way for two active MediaSessions at the same time. if another app is playing music and run MediaSession then yours doesn't have focus and isn't active... this is made for purpose - better UX - only one "player" app can play music (or video). if this wouldn't work like that and you could play music by few apps at once then how should work media button on e.g. headphones? pasuing/resuming all players? this is just not user-friendly, so Android team introduced MediaSession pattern with option for calling "focus on me now" by any app, but then another app/MediaSession pauses and doesn't get any inputs (this active session does)
if you need physical buttons presses then onKeyDown should work (inside Activity or eventually using AccessibilityService, which would work "globally" in whole system). if you need some on-screen notification buttons presses then just make custom layout for your notification with as much buttons as you like, even styled as a player
note that in Android 11 active MediaSessions notification is stickied to top of notification section when you drop down status bar. your custom notification will be somewhere below between all others (you can manipulate position a bit using priority param for notification/channel)

Android : How do I intercept Android system volume panel UI in my app?

I'm working on an app where I am looking to intercept the volume change key press and show my custom UI. Something like https://play.google.com/store/apps/details?id=leedroiddevelopments.volumepanel
So requirement is whenever use tries to change volume in my app, instead of showing system UI for volume control panel, I want to show my own UI.
How do I achieve this?
If your app is foreground, you can handle the media keys like normal keys.
https://developer.android.com/guide/topics/ui/ui-events
If the foreground app don't handle the media key, the system will handle it and show the volume ui.

Accepting Android volume rocker input across a range of states

I have an app that will generally be the sole app for which a device (Android 4.2 and up) is used. It needs to be able to accept input from the volume rockers in the following scenarios:
app is in foreground
app is in background
lock screen or keyguard has been engaged
screen has been switched off (ie idle mode).
(1) is easily solved by listening for KeyDown events in the Activity
(2) can be partially solved by listening for android.media.VOLUME_CHANGED_ACTION (yes I know it's not public API, but it works all devices I have managed to test it on and I can't find an alternate). But on my Nexus 5 (Android 6.0), on first press of the rocker it displays the volume dialog for a short duration and requires a second press to pass the rocker event to my app. I haven't managed to pin down for which version of Android this started occurring, but I'd like to work how how to ensure the first event is passed to my app for all Android versions.
(3) can be mitigated by using WindowManager FLAG_DISMISS_KEYGUARD and FLAG_SHOW_WHEN_LOCKED to avoid lock screen and keyguard
(4) can be partially mitigated by using WindowManager FLAG_KEEP_SCREEN_ON to ignore display timeouts when app is in foreground. But unfortunately it is a common event for the user to accidentally manually power the screen off, and even using a WAKE_LOCK doesn't allow the volume rocker events to be received via android.media.VOLUME_CHANGED_ACTION when the screen is idle.
So the questions are:
How do I ensure that the first press of the volume rocker is passed to my app, rather than being captured and consumed by the volume dialog?
How can I receive volume rocker events when the screen is idle?

Can i show a widget or notification that user can interact with on lock screen?

Is it possible to show some kind of widget or notification that the user can interact with without having to unlock his phone ? such as the media player on the HTC phones [Didn't use any other brand :)]
If i'm playing a song i get the play/stop options available on the lock screen and i can use them without having to unlock the screen.
Can this be done through an app in android ?

Mute (or disable) phone calls while app is running

Is it possible to mute the phone while my app is active? Or to even disable the phone call screen?
My use case is following:
I have a music player in my app and it's a fitness app, so the user does eventually not want to be disturbed. So I want to allow him to activate a "do not disturb" mode, which disables incoming call notifications, at least the sound.
What I need is following:
Bluetooth must work, because of the headphones, so plane mode would not even be a manual workaround
Can this somehow be achieved?

Categories

Resources