android-audiomanager

How does setMicrophoneMute() work?

谁都会走 提交于 2019-11-27 11:41:20
I have been trying to use Android's AudioManager.setMicrophoneMute() without much success. That is, it simply refuses to mute the microphone, no matter what I do. I searched the web for some clues and I found several references reporting similar experience: AudioManger.setMicrophoneMute functionality not working?? setMicrophoneMute(boolean) doesn't work on some devices Unable to mute the microphone in Android Which begs the question: Does AudioManager.setMicrophoneMute() work at all? Is it only a stub method, waiting to be implemented in some future version of Android? If not, how does it work

How do I register in manifest an *inner* MEDIA_BUTTON BroadcastReceiver?

怎甘沉沦 提交于 2019-11-27 08:04:59
问题 I managed to get my headset buttons get recognized by my app when pressed, but one of the buttons needs to call a method that's in MyCustomActivity. The problem is onReceive's 1st parameter is a Context that cannot be cast to Activity and so I am forced to implement my BroadcastReceiver as an inner class inside MyCustomActivity. So far so good but how do I register this inner MediaButtonEventReceiver in the manifest? For the independent class, this was simple: <receiver android:name="

Set media left/right volume separately?

时间秒杀一切 提交于 2019-11-27 04:53:07
问题 I would like to override the media left and right volume setting separately as a whole. It does not seem possible to set the left and right volume separately using AudioManager.setStreamVolume() . I noticed it is possible though to set it with MediaPlayer.setVolume() or SoundPool.play() but I would like to override the whole system media settings so the stereo balance would be kept among the different music players and applications. I'm not really familiar with Android so I would welcome all

How to get current ringtone in Android?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 03:21:01
问题 I have found lots of examples how to get default ringtone. Something like that: Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); Ringtone ringtone = RingtoneManager.getRingtone(getApplicationContext(), alert); ringtone.setStreamType(AudioManager.STREAM_RING); ringtone.play(); But I want to get the actual current ringtone, that was set by the user. 回答1: I was struggling with this issue as well, so the solution is: Uri defaultRingtoneUri = RingtoneManager

Change Media volume in Android?

女生的网名这么多〃 提交于 2019-11-27 03:11:15
Can I change the media volume? and how? I used this so far: setVolumeControlStream(AudioManager.STREAM_MUSIC); But have a seekbar and want to change the media volume, not ring volume. So can someone show me how to just change the media volume at onCreate() and I fix the seekbar later. The right method to use would be setStreamVolume on your AudioManager . It could looks like this AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, [int value], [if desired a flag]); An example use of the flag is to get the

Android : Force audio routing

[亡魂溺海] 提交于 2019-11-26 22:00:29
问题 I would like to change the sound device output in my Android app. I want to use the speaker of the phone when the headset plugged. I've tried to use setSpeakerphoneOn from AudioManager class audioManager.setSpeakerphoneOn(true); with audioManager.setMode(AudioManager.MODE_IN_CALL); but I don't want to set the MODE_IN_CALL ! I want to stay in MODE_NORMAL. I've search around the AudioSystem class and I've found an application, "SoundAbout", which do that. You can choose the speaker for media

Android: Voice Recording and saving audio

若如初见. 提交于 2019-11-26 20:58:53
问题 I am working on application that will record the voice of the user and save the file on the SD card and then allow the user to listen to the audio again. I am able to allow the user to record his voice using the RecognizerIntent, but I cant figure out how to save the audio file and allow the user to hear the audio. I would appreciate it if someone could help me out. I have displayed my code below: // Setting up the onClickListener for Audio Button attachVoice = (Button) findViewById(R.id

How to Play audio through speaker even when headset is plugged in?

给你一囗甜甜゛ 提交于 2019-11-26 20:23:58
问题 The title of the question might look repeated, but my problem is a sometimes problem and causes glitches. I have used the below code to play through speaker when headset is plugged in. AudioManager audioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); audioManager.setMode(AudioManager.STREAM_MUSIC); audioManager.setSpeakerphoneOn(true); if(! Globals.mediaPlayer.isPlaying()){ Globals.mediaPlayer.start(); } The above code plays audio in the following ways: 1. Very few

In Android 7 (API level 24) my app is not allowed to mute phone (set ringer mode to silent)

自古美人都是妖i 提交于 2019-11-26 18:49:19
I have an app that mutes the phone by using AudioManager and setting ringer mode to silent with this code: AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); try { audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT) } catch (Exception e) { e.printStackTrace(); } This works with Android 6, but now with Android 7, I get the following error: System.err: java.lang.SecurityException: Not allowed to change Do Not Disturb state System.err: at android.os.Parcel.readException(Parcel.java:1683) System.err: at android.os.Parcel.readException(Parcel.java

setStreamMute never unmutes

早过忘川 提交于 2019-11-26 18:30:27
问题 In the documentation, it is said: The mute command is protected against client process death: if a process with an active mute request on a stream dies, this stream will be unmuted automatically. The mute requests for a given stream are cumulative: the AudioManager can receive several mute requests from one or more clients and the stream will be unmuted only when the same number of unmute requests are received. Well, the first paragraph is true; Whenever my process dies, all of the streams I