Set maximum audio level, don't need alert message - android

I have an audio app which will drive an external audio amplifier. In the code I set the maximum audio level:
int maxAudioVolume = audioManager.getStreamMaxVolume(AudioManager.STREA M_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_M USIC,maxAudioVolume,0);
If I plug in the amplifier, then always the following alert is issued:
Raise volume above recommended level?
This is becoming irritating. Does anybody know how the alert can be avoided? Actually, this issue has been addressed in other forums, and sometimes it was solved, but always by using some app. Thus it should be possible, but the question is: how?
Wouter Boeke

See this:
Disable sound safe level notification in android & xda-developers; Unsafe Volume - disable safe media volume popup/check
Basically you need to root your phone, and set config_safe_media_volume_enabled at boot time to false. Which happens I think if the user clicks ok, you can't get rid of it without root.

Related

Retrieving the application name that has audio focus change

I can't seem to find anything related to finding out what application got audio focus. I can correctly determine from my application what type of focus change it was, but not from any other application. Is there any way to determine what application received focus?
"What am I wanting to do?"
I have managed to record internal sound whether it be music or voice. If I am currently recording audio no matter the source, I want to determine what application took the focus over to determine what my application need's to do next.
Currently I am using the AudioManager.OnAudioFocusChangeListener for my application to stop recording internal sounds once the focus changes, but I want the application's name that gained the focus.
Short Answer: There's no good solution... and Android probably intended it this way.
Explanation:
Looking at the source code, AudioManager has no API's(even hidden APIs) for checking who has Audio Focus. AudioManager wraps calls to AudioService which holds onto the real audio state. The API that AudioService exposes through it's Stub when AudioManager binds to it also does not have an API for querying current Audio Focus. Thus, even through reflection / system level permissions you won't be able get the information you want.
If you're curious how the focus changes are kept track of, you can look at MediaFocusControl whose instance is a member variable of AudioService here.
Untested Hacky Heuristic:
You might be able to get some useful information by looking at UsageStats timestamps. Then once you have apps that were used within say ~500ms of you losing AudioFocus you can cross-check them against apps with Audio Permissions. You can follow this post to get permissions for any installed app.
This is clearly a heuristic and could require some tuning. It also requires the user to grant your app permissions to get access to the usage stats. Mileage may vary.
Looking at the MediaContorller class (new in lollipop, available in comparability library for older versions).
There are these two methods that look interesting:
https://developer.android.com/reference/android/media/session/MediaController.html#getPackageName()
https://developer.android.com/reference/android/media/session/MediaController.html#getSessionActivity()
getPackageName supposedly returns the current sessions package name:
http://androidxref.com/5.1.1_r6/xref/frameworks/base/media/java/android/media/session/MediaController.java#397
getSessionActivity gives you a PendingIntent with an activity to start (if one is supplied), where you could get the package as well.
Used together with your audio listener and a broadcast receiver for phone state to detect if the phone is currently ringing you might be able to use this in order to get a more fine grained detection than you currently have. As Trevor Carothers pointed out above, there is no way to get the general app with audio focus.
You can use dumpsys audio to find who are using audio focus. And, you can also look into the results of dumpsys media_session.
And, if you want to find who're playing music, you can choose dumpsys media.audio_flinger. For myself, I switch to this command.

How can I access the audio 'Priority Mode' on a device running Android 5.0?

Android 5.0 includes a new way to control which apps are allowed to make noise on your device: when you press the volume button, the popup now lets you to choose None (completely silent), Priority (only priority notifications make sound), or All (everything is allowed to make noise.)
I would like my app to be able to query the device to find out which of these three modes is currently active, and also I would like to be able to change these modes (without requiring the device to be rooted). Does anyone know how to do this?
So far, all I can find is a brief reference on this changelog:
Setting the device to RINGER_MODE_SILENT causes the device to enter the new priority mode. The device leaves priority mode if you set it to RINGER_MODE_NORMAL or RINGER_MODE_VIBRATE.
This works as described, which allows me a very limited ability to change "priority mode" by modifying the ringer mode in AudioManager. That's not enough, though, as I need to be able to know exactly which of the three priority mode settings is currently active, and it would also be nice if I could change them more precisely than AudioManager allows.
I've found a solution, but this requires root to change, because this setting is in Settings.Global.
Name of setting is "zen_mode".
Values are:
ZENMODE_ALL = 0;
ZENMODE_PRIORITY = 1;
ZENMODE_NONE = 2;
EDIT: I've found another solution. Check NotificationListenerService.requestInterruptionFilter(int interruptionFilter). https://developer.android.com/reference/android/service/notification/NotificationListenerService.html
Implementation example: https://github.com/kpbird/NotificationListenerService-Example

Alternative to READ_PHONE_STATE permission for getting notified of call

I'm currently using the READ_PHONE_STATE permission in Android to pause my media player when there's a call, and to resume playback when the call is over. The permission seems to scare a lot of people, so I was wondering if there was an alternative to catching the starting and stopping of a phone call without it. Any help is appreciated. Thanks!
If you want to adjust your audio output in response to something else wanting to perform audio output (e.g., an incoming phone call), look into Android's audio focus support.
READ_PHONE_STATE, as noted, is a bit of a scary permission. Moreover, it only deals with phone calls, and not other things that might need the same capability (e.g., VOIP calls, as AFAIK those don't tie into READ_PHONE_STATE-enabled stuff).
Unfortunately, audio focus is not a substitute for READ_PHONE_STATE. My app has to use both. The standard phone app on my Galaxy S3 I9300/ Android 4.3 doesn't seem to request the audio focus at all. The TelephonyManager class gives you a way to detect the end of the phone call (by sending the CALL_STATE_IDLE state update). The AudioManager doesn't seem to do anything similar, so even if audio focus could be used, it would not be as useful. And, from what I see in the documentation, there doesn't seem to be a narrower permission than READ_PHONE_STATE that would allow the app to read the phone state but not the call information. If I'm wrong about any of this, please correct me.
Unfortunately, audio focus is not a substitute for READ_PHONE_STATE. My app has to use both. The standard phone app on my Galaxy S3 I9300/ Android 4.3 doesn't seem to request the audio focus at all. The TelephonyManager class gives you a way to detect the end of the phone call (by sending the CALL_STATE_IDLE state update). The AudioManager doesn't seem to do anything similar, so even if audio focus could be used, it would not be as useful. And, from what I see in the documentation, there doesn't seem to be a narrower permission than READ_PHONE_STATE that would allow the app to read the phone state but not the call information. If I'm wrong about any of this, please correct me.

AudioManager - difference between two methods

What is the difference between calling AudioManager.setRingerMode to calling AudioManager.setStreamMute(AudioManager.STREAM_VOICE_CALL, ...)
What does the documentation mean by "Ringer mode"? I'm pretty sure it is the phone ringer mode. Then how does it differ from calling setStreamMute with STREAM_VOICE_CALL?
If it is not the phone ringer mode, then what is it?
Thanks in advance.
I have never used the audio stream on the android platform, however, based on reading the documentation, I think setRingerMode will affect how the phone reacts to incoming calls. For example, AudioManager.setRingerMode(RINGER_MODE_SILENT) will disable vibrations and sound when an incoming call is received.
However, AudioManager.setStreamMute seems to control more than just the audio stream for phone rings.
From the documentation at http://developer.android.com/reference/android/media/AudioManager.html#STREAM_VOICE_CALL
I think that AudioManager.setRingerMode(RINGER_MODE_SILENT) will act the same way as AudioManager.setStreamMute(STREAM_RING, true).
I think the best way to see what the difference is (nd to see if what I am saying is true) would be to write a small program that tests the two features.

Is there a way to to create a custom answering machine in android?

I'd like to create an app that allow you to filter incoming call to various answering message with :
"this number is not available" for black listed phone numbers
A formal message for strangers
A informative message about what your doing for friends
I don't know how you can get automatically a call, play a recorded message then wait for the answer and record it. Or maybe there is just a way to interact with the actual answering system so I just have to plugin.
Any clue strongly appreciated. A human sacrifice for any code snippet :-)
Access to the internal telephony is not possible or planned for future releases of Android:
http://groups.google.com/group/android-developers/browse_thread/thread/e8904c82a2c4a333
This would present a security risk as app developers could intercept and hijack sensitive calls (eg. telephone banking)
This is not possible on the tmobile G1 at this time. There is no way for an android SDK application to access the call input or output on this hardware/firmware combination.
http://groups.google.com/group/android-developers/browse_thread/thread/d04c307973345fef/a628e578900b3dce?lnk=gst&q=dave+sparks+play+audio#a628e578900b3dce
and
http://groups.google.com/group/android-developers/browse_thread/thread/185e33a3f420d1ac/e14e1dc84bb6dd24?lnk=gst&q=play+sound+call#e14e1dc84bb6dd24
I'm not sure this answers the question, but it is somewhat related I think.
You can install Ultimate Voice Recorder which can record your conversations (very useful when calling customer 'service'). Since it can record it, it must have some way to access the conversation.
Also, the capabilities you have to give the app are quite scary (translated from dutch: full internet access, intercept outgoing calls, change preferences, call phone numbers directly, record audio/take pictures, update contacts, auto startup). It seems to me there must be something in there that can help you?
However, I don't think it can inject audio into the stream. The symbian version had an option to insert beeps into the conversation, but I don't think the android version has it.
http://www.fingertip-access.com/
I have found out att for this use of your Phone Android or ISO, so far they ar decades behinde symbian and an inferior alternativ sadly, if you don't install a custom kernel/jailbreak it's not possible to record incoming calls and screen them. "Ultimate Voice Record ned you to use the phone in speaker mode."
it is possible to record voice calls with automatic answer. An update on this issue would be very helpful...
It is possible to have a resource that answers the calls. Enter a message and record the call. And together don't activate the microphone...
In short, an answering machine...

Categories

Resources